• Resolved melvyn

    (@melvyn)


    Hi all!

    I’m using this for my next/previous link instead of the standard next_post_link/previous_post_link because I needed to style the link:

    <div id="post-nav-next"><a href="<?php $nextPost = get_next_post(true); echo get_permalink($nextPost->ID); ?>#post-content"></a></div>
    <div id="post-nav-previous"><a href="<?php $prevPost = get_previous_post(true); echo get_permalink($prevPost->ID); ?>#post-content"></a></div>

    The problem with this is that the previous link still shows up in the last post and likewise the next link is there in the first post. How do I disable or hide this? I presume it involves the “if” php function but I’m still no good with php yet.

    Any help would be appreciated. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter melvyn

    (@melvyn)

    Actually, I used this rather than the next_post_link/previous_post_link so that I can add the jump anchor “#target” to the link.

    Anyone?

    Thread Starter melvyn

    (@melvyn)

    Found a solution from a previous topic and modified it to this:

    <div id="post-nav-previous">
    <?php $next_post = get_next_post(true); if($next_post) { echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '#post-content"></a>' . "\n"; } ?>
    </div>
    
    <div id="post-nav-next">
    <?php $prev_post = get_previous_post(true); if($prev_post) { echo "\t" . '<a rel="next" href="' . get_permalink($prev_post->ID) . '#post-content"></a>' . "\n"; } ?>
    </div>

    Worked like a charm!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable “previous link” in last post and “next link” in first post’ is closed to new replies.