WordPress.org

Ready to get started?Download WordPress

Forums

Passing an linked anchor through pagination? (3 posts)

  1. SpankMarvin
    Member
    Posted 3 years ago #

    Hello!

    I have a gallery that shows 9 thumbnails per page, and is often paginated. In instances where there is a filter passed to the query, I am having the page shift down to a named anchor (#togallery) so that the user sees the content rather than all the header stuff.

    No problems there, except that when it paginates (using next_posts_link) the anchor does not carry over, and I'd like it to, if possible.

    Does anyone have any ideas about how to achieve this? I'd be grateful for any pointers.

    Thanks

    John

  2. AMGill
    Member
    Posted 2 years ago #

    I'm looking for the same thing.

  3. riki81
    Member
    Posted 2 years ago #

    Check this!

    <?php
    $the_last_page = $wp_query->max_num_pages;
    $loaded_page = intval($paged);
    ?>
    <?php if ( $the_last_page == $loaded_page) { // if is the last page ?>
    <div class="navigation_previous"><a href="<?php previous_posts(); ?>#box2">&laquo;</a></div>
    <?php } elseif ($loaded_page == 0) { // if is home ?>
    <div class="navigation_next"><a href="<?php next_posts(); ?>#box2">&raquo;</a></div>
    <?php } else { //otherwise ?>
    <div class="navigation_previous"><a href="<?php previous_posts(); ?>#box2">&laquo;</a></div><div class="navigation_next"><a href="<?php next_posts(); ?>#box2">&raquo;</a></div>
    <?php }  // links to newer and older posts ?>

    It is valid for next-posts() and previous_posts(), typical in HOME PAGE, but not for next_post_link() and previous_post_link(), both used in SINGLE POST template.
    I'm looking for the same solution, but for SINGLE POST page navigation (from one post to another one).

    Hope has been useful! ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic