Paginate through posts of a single category in Wordpress single.php

James Howell picture James Howell · Jul 18, 2011 · Viewed 11.2k times · Source

I have set up a site using Wordpress as my CMS. I am using the site as a portfolio to show off my front-end web dev skills and have another area of the site for a blog. I got around the issue of having 2 blogs on the site by giving posts a category of either Projects or Blog.

The front page of my site contains thumbnails and links to Recent Projects. When you click through you are taken to a Project Detail page which uses Single.php to display a single post. The TwentyTen theme (which I have edited) comes with pagination so that when you are on the Project Detail page you can also click through to the next or previous post. However there does not seem to be any restriction on the category so you can also click through to Blog posts. I want the user to only be able to click through to other Projects.

I have googled around this issue and seem to find suggestions to use custom queries but none of the solutions suggested seem to work.

I only want to display one post at a time on Single.php and have pagination which lets me link to the next or previous Project post.

Any ideas?

Answer

Mike picture Mike · Nov 24, 2011

Checkout these links: http://codex.wordpress.org/Function_Reference/previous_post_link http://codex.wordpress.org/Function_Reference/next_post_link

This is an example of how you can use the function to restrict to posts in current cat only:

<?php previous_post_link('%link', 'Next: %title &raquo;' , in_same_cat, 'excluded_categories '); ?>
<?php next_post_link('%link', '&laquo; Previous: %title', in_same_cat, 'excluded_categories '); ?>