categories - previousnext_post_link in the same sub-category?

admin2025-06-04  2

As the title: is there a way to navigate between posts of the same subcategory using the previous_post_link and next_post_link functions? But maintaining however both the category and the sub-category of the post.

As the title: is there a way to navigate between posts of the same subcategory using the previous_post_link and next_post_link functions? But maintaining however both the category and the sub-category of the post.

Share Improve this question edited Jan 24, 2019 at 7:52 claudio asked Jan 23, 2019 at 15:34 claudioclaudio 1116 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you’ll take a look at next_post_link Codex page, you’ll see it’s usage:

<?php
next_post_link(
    $format,
    $link,
    $in_same_term   = false,
    $excluded_terms = '',
    $taxonomy       = 'category'
);

As you can see, third param is in_same_term and it’s default value is false. If you set it to true, then the function will return next post from same category. (If you want the term from different taxonomy, you can change fifth param).

So answering your question... Yes, there is a way to achieve this. It can look like so:

<?php next_post_link( '%link &raquo;', '%title', true ); ?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748979855a315345.html

最新回复(0)