I am setting up a new WordPress site, with issue-specific articles. I’m attempting to set up some next/last buttons within the posts that cycle through posts in a specific category.
In case it’s not clear, here’s what I’ve got for this issue:
Spring 2016 (slug 2016-spring) - 2 unique posts (6 total)
Feature (slug feature-2016-spring) - 2 unique posts
Images (slug images-2016-spring) - 1 unique post
President's Message (slug president-2016-spring) - 1 unique post
And then this fall, I’ll have pretty much an identical setup with slugs of 2016-fall, etc.
I want my post’s next and last buttons to only cycle through posts that contain that parent category. Every Feature, for example, is assigned both the Feature and the Spring 2016 category, so they’re all listed within the parent category. But when I get to the President’s Message, I want the “Next” button to loop me back to the first post in the category.
This is the current div I’m using for my navigation; is it easy to plug this in to there?
<div class="post_nav">
<a href="#"><div class="last">Last</div></a>
<a href="<?php bloginfo('url'); ?>"><div class="home"> </div></a>
<a href="#"><div class="next">Next</div></a>
</div>
You can use the WordPress functions previous_post_link() and next_post_link(). By default, they’ll interact with the parent categories.
I’m assuming you have the divs for styling purposes, so go with something like this: