• This is what I want –

    After clicking a Post in the list, it should auto scroll down to reveal the first half of it along with the heading. Right now only the Post heading is being displayed at the bottom, after clicking a Post.

    It’s certainly not user-friendly to repeatedly scroll down manually to view the rest of the post.

    Just in case it matters, let me give you some additional info:

    1 – We are working on a Multisite environment having more than 300 sites.
    2 – We are using the Archy theme for most of our sites.

Viewing 15 replies - 1 through 15 (of 21 total)
  • Chad

    (@lynneandchad)

    Why is the post title so low on your page? Any chance you can post a link?

    This is just a quick thought, but you could modify content.php (pereferably with a child theme) to link to an anchor that would put your title at the top. perhaps #wrapper? Line 23 ought to be the one to change.

    Thread Starter rajesh0228

    (@rajesh0228)

    Hi Chad, thanks for your post. At last someone has responded!


    Here is the link
    you wanted to see.

    What exactly do you mean by “post title so low on your page”?

    Thread Starter rajesh0228

    (@rajesh0228)

    Chad, can you please post a sample code for the kind of action I want.

    Chad

    (@lynneandchad)

    Okay, line isn’t going to be where you need to look – your child theme’s structure is modified a bit from the parent.

    Is this how you want the posts to load when someone clicks a link on the home page?

    https://powdev.biz/blog/home-garden-care-uk/what-is-good-garden-soil/#mid-top

    Basically linking to that spot on the page so more of the content is visible.

    If so, you need to modify the links being created in the loop slightly. Rather than:

    <a href="<?php the_permalink(); ?>"> ...

    you’d use:
    <a href="<?php the_permalink(); ?>#mid-top"> ...

    If you’d like a more elegant but more involved solution, you could also set up a different template for single posts/pages that has a smaller header.

    Unrelated note – You’ve proobably already noticed this, but there’s an image of a flower and a watering can that is split between the header image and the navigation bar. The bottom of the flower isn’t aligned properly with the top. It needs to shift to the left a bit ??

    Thread Starter rajesh0228

    (@rajesh0228)

    Hi Chad, yes that is precisely the kind of solution I want! The post is loading & showing 50% of it automatically.

    But what about this “#mid-top”? Is it something you’ve just appended to the URL to get the result? Is there anything else you did?

    In which file (s) should the following code exist: “#mid-top”>”?

    Regarding your “more elegant but more involved solution”, I will check it out later.

    PS: Thanks for pointing out the the “overlap” of the white flower at the bottom of the Header image on the navigation bar.

    Chad

    (@lynneandchad)

    No problem.

    mid-top is an anchor that exists on your page. by adding a reference to it at the end of the url you are linking directly to that section of the page.

    The problem we have is that your links are being generated in the sidebar by a recent-posts widget.

    This code should replicate the widget fairly well – you might need to adjust the styling on your end, but I tried to match it up as best I could:

    <aside id="custom-recent-posts" class="widget">
        <h1 class="widget-title">Recent Posts</h1>
        <ul>
          <?php
          $postslist = get_posts('numberposts=5');
          foreach ($postslist as $post) {
            setup_postdata($post); ?>
            <li><a href="<?php the_permalink(); ?>#mid-top"><?php the_title(); ?></a></li>
         <?php } ?>
        </ul>
      </aside>

    That should give you a list of five links with the #mid-top anchor appended to them.

    Add it your child theme’s sidebar.php file. this block goes immediately between these two lines:

    <div id="secondary" class="widget-area">

    and

    <?php if ( is_active_sidebar( 'sidebar-1' ) ) :

    Note: placing it here means your new custom widget will always appear, even if you remove all of the other widgets – which would normally disable the sidebar.

    You can place it inside the conditional, just make sure you open and close the php tags properly ??

    Thread Starter rajesh0228

    (@rajesh0228)

    Chad my Sidebar.php code looks like this –

    <div id="secondary" class="widget-area" role="complementary">
    
     <?php if ( has_nav_menu( 'secondary' ) ) : ?>
    
     <nav role="navigation" class="navigation site-navigation secondary-navigation">
    
      <?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>
    
     </nav>
    
     <?php endif; ?>
    
        <?php if (!dynamic_sidebar('home-widgets')) : ?>
    
          <p>&nbsp;</p>
    
        <?php endif; // end sidebar widget area  ?>
    
    </div>

    But your code “<?php if ( is_active_sidebar( ‘sidebar-1’ ) ) :” does not exist. What to do now? Where do i insert your block of code?

    Chad

    (@lynneandchad)

    Interesting. The copy of Archy I downloaded for this is very different from your setup.

    Try placing the code immediately before

    <?php if (!dynamic_sidebar('home-widgets')) : ?>

    Let me know how it goes!

    Thread Starter rajesh0228

    (@rajesh0228)

    Chad, I followed your last suggestion.

    It is working! Thanks!

    But I’ve an interesting problem: I am now having 2 Recent Posts lists. And it is the first one which is working, not the second one.

    Now what do I do?

    Chad

    (@lynneandchad)

    The second (original) list looks like a sidebar widget.

    Go to Appearance -> Widgets and look remove the Recent Posts widget from the sidebar.

    Thread Starter rajesh0228

    (@rajesh0228)

    I have removed the Recent Posts sidebar widget. Now I only have the Recent Posts which I’d created using your code.

    Everything’s fine now.

    So should I now apply the same technique in the sidebar.php file of any Theme I use in the future? Is there any thing else I need to look out for?

    Chad

    (@lynneandchad)

    You shouldn’t need to do this to every theme – this one just has a very large header image.

    With a shorter header, more of the post would be visible.

    Also, on a different theme you’d need to use a different anchor. #mid-top is specific to this theme.

    You can look for an anchor to use by right clicking on an element of your page and looking for your browser’s “Inspect Element” or similar option.

    Thread Starter rajesh0228

    (@rajesh0228)

    In this example, is the anchor “#art-main”?

    Chad, may I know how exactly do I detect the “anchor”? In what kind of code should it exist? Or should i just experiment and find out for myself?

    And after finding it can I include it in your code and then insert it in the sidebar.php file of any Theme (before
    ?php if (!dynamic_sidebar('home-widgets')) : ?
    as you’d suggested)?

    Chad

    (@lynneandchad)

    On that site the #art-main anchor will work, yes.

    Basically, when you are inspecting the elements on your site you can use this method to link to any element with an ID set ("id=art-main").

    For Archy child themes, the code you have should work pretty consistently, on other themes there may be differences, but you should be close enough to piece it together if you have to ??

    Thread Starter rajesh0228

    (@rajesh0228)

    >> “on other themes there may be differences”

    You mean instead of sidebar.php it can be some other file?
    Instead of <?php if (!dynamic_sidebar('home-widgets')) : ?> it could be something else?

    And what about your own block of code? Should that remain the same for other themes (with the exception of the anchor value in it)?

    PS: Are you getting email notifications of my postings? I am not getting any for yours? What is the problem?

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Automatically scroll down Post’ is closed to new replies.