- This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
Viewing 7 posts - 1 through 7 (of 7 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
In WordPress, on the Single Post page, there is “Older Post” and “Newer Post” navigation links. It goes to the previous and next post. Is there a way to make sure those links skips over posts from a specific category?
No problem! Before the loop in your single.php, you’ll want to add in something like this:
Changing the number to the ID of the category you’d like to exclude.
@TheDoc, normally that would be the simple answer. But the Single Post page isn’t a loop. And the “Older Post” and “Newer Post” are just straight Links. Here’s the code to the page.
/**
* The Template for displaying all single posts.
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
get_header(); ?>
The “get_template_part” line doesn’t matter, it just fetches the Single Post html. What matters is that navigation that goes to the previous and next post. It takes all posts into account and I want it to ignore posts from a specific category
It certainly looks like a loop to me! Just put the query above your ‘while’ statement.
I tried putting it in and it started displaying the 5 most current posts that don’t include that category. So I added “&showposts=1” to the remove category and so its just showing the most current post.
Thanks for the Help TheDoc.
I did a bit of reading the WP Codex (not sure why I didn’t before) and apparently both “previous_post_link()” and “next_post_link()” have an option inside to exclude categories and to even keep the links limited to 1 category.
Man, wordpress has a ton of options :)
I didn’t know that one either, sweet!