Specify category for next/prev_post_link
-
I need to restrict the categorie for the next/prev_post_link tag, since I’ve got some posts within two or more categories.
I’m thinking about doing it with an IF statement, like this:
<?php if ( in_category(4) ) {
next_post_link();previous_post_link();
} elseif ( in_category(2) ) {
next_post_link();previous_post_link();
}
?>But there I’ve got no control whether the post in categories 3 and 4 prints the previous link only for the category 4 as desired.
So, is there a way to restrict the next_post_link to a specific category? This is the concept:
<?php if ( in_category(4) ) {
next_post_link(-for cat. 4-);previous_post_link(-for cat. 4-);
} elseif ( in_category(2) ) {
next_post_link(-for cat. 2-);previous_post_link(-for cat. 2-);
}
?>
- The topic ‘Specify category for next/prev_post_link’ is closed to new replies.