Title: Continuous Loop for &#8220;Previous&#8221; and &#8220;Next&#8221; Posts
Last modified: November 16, 2022

---

# Continuous Loop for “Previous” and “Next” Posts

 *  [keempoo](https://wordpress.org/support/users/keempoo/)
 * (@keempoo)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/continuous-loop-for-previous-and-next-posts/)
 * Absolutely love this theme for a portfolio site!
 * Is it possible to get some input on how you would best change the pagination 
   code so that the most recent post (“/girls-girls-girls”) would show both the “
   next post” (the second latest post) as well “the previous post” (which would 
   be the earliest post). It currently only shows the “Next Post”
 * Eskell’s pagination code:
 * // The pagination links also work as a no-js fallback, so they always need to
   be output.
    $prev_link = get_previous_posts_link( ‘<span class=”arrow stroke-
   cc”>’ . eksell_get_theme_svg( ‘ui’, ‘arrow-left’, 96, 49 ) . ‘</span><span class
   =”screen-reader-text”>’ . esc_html__( ‘Previous Page’, ‘eksell’ ) . ‘</span></
   span>’, $query_args[‘max_num_pages’] ); $next_link = get_next_posts_link( ‘<span
   class=”screen-reader-text”>’ . esc_html__( ‘Next Page’, ‘eksell’ ) . ‘</span>
   </span><span class=”arrow stroke-cc”>’ . eksell_get_theme_svg( ‘ui’, ‘arrow-right’,
   96, 49 ) . ‘</span>’, $query_args[‘max_num_pages’] );
 *  if ( $prev_link || $next_link ) :
    $pagination_class = ! $prev_link ? ‘ only-
   next’ : ( ! $next_link ? ‘ only-previous’ : ” ); ?>
 *  <nav class=”link-pagination<?php echo esc_attr( $pagination_class ); ?>”>
 *  <?php if ( $prev_link ) : ?>
    <div class=”previous-wrapper”> <?php echo $prev_link;?
   > </div><!– .previous-wrapper –> <?php endif; ?>
 *  <?php if ( $next_link ) : ?>
    <div class=”next-wrapper”> <?php echo $next_link;?
   > </div><!– .next-wrapper –>
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcontinuous-loop-for-previous-and-next-posts%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Theme Author [Anders Norén](https://wordpress.org/support/users/anlino/)
 * (@anlino)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/continuous-loop-for-previous-and-next-posts/#post-16250663)
 * Hi [@keempoo](https://wordpress.org/support/users/keempoo/),
 * I’m glad you like it! I assume you mean the post navigation shown when you’re
   viewing a single post, correct?
 * There’s no easy way to accomplish this, unfortunately. In simple terms, you’d
   have to update single-post-navigation.php to check if either `$nav['prev']` or`
   $nav['next']` is false, and then get either the most recent post in the chronology(
   for the previous link) or the oldest (for the next link).
 * This plugin could be useful to simplify the custom code needed: [https://wordpress.org/plugins/loop-post-navigation-links/](https://wordpress.org/plugins/loop-post-navigation-links/)
 * — Anders

Viewing 1 replies (of 1 total)

The topic ‘Continuous Loop for “Previous” and “Next” Posts’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/eksell/1.9.5/screenshot.png)
 * Eksell
 * [Support Threads](https://wordpress.org/support/theme/eksell/)
 * [Active Topics](https://wordpress.org/support/theme/eksell/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/eksell/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/eksell/reviews/)

## Tags

 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * 1 reply
 * 2 participants
 * Last reply from: [Anders Norén](https://wordpress.org/support/users/anlino/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/continuous-loop-for-previous-and-next-posts/#post-16250663)
 * Status: not resolved