Support » Fixing WordPress » Get Next Post or First Post

  • I have the following code which should display the next post or the first post if it is the last post.

    <?php
    $next = next_post_link('%link', 'Next Game');
    
      if($next == null){
    
    	echo '<a rel="first" href="'.get_permalink(4).'">Next Game</a>';
    
      }else{
    
    	 echo next_post_link('%link', 'Next Game');
      }
    ?>

    It works well except on posts where it is NOT the last post t displays two links: NextGameNext Game

    linking to both the next post and the first post!

    On the last post it correctly displays a link to the first post. I can’t understand how it is pulling two links for posts that are not the last post.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Get Next Post or First Post’ is closed to new replies.