next_post_link(); with anchor (5 posts)

  1. riki81
    Posted 4 years ago #

    Hi, I need to let the user jump directly to an exact point navigating from post1 to post2, etc.
    Normally, I use:

    <div class="navigation_previous"><?php next_post_link( '%link', __( '&laquo;', 'twentyeleven' ) ); ?></div>
    <div class="navigation_next"><?php previous_post_link( '%link', __( '&raquo;', 'twentyeleven' ) ); ?></div>

    but this give in out put sth like http://DOMAIN/?p=POSTID
    What I really need id http://DOMAIN/?p=POSTID#anchor to let the user open the post directly at the correct level of the page.

    Thanks to everyone can help me! Greetings!

  2. Tara
    Volunteer Moderator
    Posted 4 years ago #

    see if info in this thread helps.

  3. riki81
    Posted 4 years ago #

    Thanks for quick reply!
    I knew that thread, and I used it a lot for POSTS navigation (normally used in home page) with "previous_posts_link", etc... but I need to do the same for SINGLE POST page with "previous_post_link".

    It sounds ridiculous, but actually it seems so different! :-(

    Waiting for someone help!!! Thanks t-p! ;-)

  4. Tara
    Volunteer Moderator
    Posted 4 years ago #

  5. riki81
    Posted 4 years ago #

    Hi, I've checked, but nothing... the problem is that previous_post_link generates entire link, so I am not able to do sth like previous_post_link#anchor.

    For HOME I did:

                                    $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 ?>

    but for single one I cannot do, 'cause previous_post is deprecated function! :-(

    Any other solution? Maybe a good programmer, looking at previous code I've shared above, could think sth of useful for my situation... ;-)

    Thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic