$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - previousnext_post_link in the same sub-category?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - previousnext_post_link in the same sub-category?

matteradmin7PV0评论

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 ); ?>
Post a comment

comment list (0)

  1. No comments so far