3

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)?

5

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! – ajh158 Sep 5 '14 at 2:10
0

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 );

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.