12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Aug 5, 2021

Adjacent Posts Navigation with Infinite Looping in WordPress

Sridhar Katakam

This members-only tutorial provides the steps to set up links to previous and next posts on single posts (can be of any post type incl. Pages) whilst ensuring that

  • if there is no previous post, the first post is shown and
  • if there is no next post, the last post is shown

essentially for an infinite looping of adjacent posts.

For example, given these posts:

when Post 3 is being viewed, the previous post would be Post 2 and the next would be Post 4.

when Post 4 is being viewed, the previous post would be Post 3 and the next should be Post 1 and not blank.

and when Post 1 is being viewed, the previous post should be Post 4 and not blank and the next would be Post 2.

While the tutorial has been written for Oxygen, the instructions can be used in any WordPress site.

Step 1

Edit the Template that applies to singular posts.

Add a Code Block and set its width to 100%.

Give it a class of adjacent-posts.

PHP & HTML:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-ocalendar-check-omagnifiercrossmenuchevron-downarrow-right