WordPress: Paginate Posts Within Category

In Wordpress Tutorials by Laura

On my blog I have a number of different sections that don’t always relate to each other. WordPress categorizes all of these as simply “posts” and unless you add some customization – the on page pagination from post to post can be misleading.

Locate your single.php file in your themes folder. It is best practice to use a child theme so that when your theme runs updates your customizations are not overwritten.

You should see a section commented out about post navigation. Some themes will include code that looks like this:

Screen Shot 2014-01-07 at 8.19.45 PM

You can see that the previous_post_link is calling the link and the title of the previous post. This is based off the time when you published each post. Adding in the word “TRUE” will limit the post to link only to the previous post within the same category.

Just add in the code below and your pagination should paginate only within the category that the post is in.

wordpress pagination

WordPress’s Codex does a great job of explaining this as well and they show various other ways to use “previous_post_link” and “next_post_link”: http://codex.wordpress.org/Function_Reference/next_post_link