Is it possible to force previous/next navigation to browse through the posts (back and forth) that are only inside the same category (and to exclude other categories)?
2 Answers
The functions accept an $in_same_cat
argument, the default value of which is false. Just set that to true.
previous_post_link($format, $link, true);
next_post_link($format, $link, true);
-
Thanks! My wife asked for this and your answer made it a 10 minutes job to customize my child theme!– ajh158Sep 5, 2014 at 2:10
You can use the following code in single.php loop to display nex/pre links in same category
<?php
get_template_part( 'content', get_post_format() );
// Previous/next post navigation.
previous_post_link('%link', 'Before', true );
next_post_link( '%link', 'Next', true );
?>