WordPress.org

Ready to get started?Download WordPress

Forums

Next Post Link - End of posts (5 posts)

  1. bremmerm
    Member
    Posted 2 years ago #

    I am utilizing the following code to navigate between posts:

    <?php next_post('%', 'Next Game', 'no'); ?>

    The problem is, when it get's to the last post it is empty. How can I loop it back to the first post??

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    next_post() is a deprecated function, try next_post_link()

    <?php next_post_link('%link', 'Next Game'); ?>

    to show a previous post link use previous_post_link()

    <?php previous_post_link('%link', 'Previous Game'); ?>
  3. bremmerm
    Member
    Posted 2 years ago #

    Okay - Thanks for the tip. But same problem, when it reaches the last post, the next post is empty. I need to go back to the first post not in reverse(previous post).

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    This checks if there is a next game post, and if there isn't one it links back to the latest post:

    <?php
    $next = get_adjacent_post( false, '', true );
      if(!$next){
        $latest_post = get_posts('posts_per_page=1');
        if($latest_post) {
          echo '<span class="nav-previous"><a rel="first" href="'.get_permalink($latest_post[0]->ID).'">First Game</a></span>';
        }
      }
    ?>
  5. bremmerm
    Member
    Posted 2 years ago #

    Hmmm, i tried out the code but did not work..

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.