Restrict previous and next posts within same category or tag

I am trying to modify the navigation feature of my wordpress, to restrict the pre and next links within the same taxonomy(tag or category),after searching several measures,here is my final resolution:

modify the navigation code:

I am using Twentysixteen theme, first find the file address: Single(single post.php) in Theme Editor.

then find the the_post_navigation() expression,

you can see the expression like this:

the_post_navigation(
                    array(
                        'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
                            '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
                            '<span class="post-title">%title</span>',
                        'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
                            '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
                            '<span class="post-title">%title</span>',
                        'in_same_term' => 'true',
                    )
                );

add 'in_same_term' => 'true',in the array expression, which means the posts(next or pre) are limited in the same term, u can also add extra argument, like 'taxonomy' => '_post_tag'.

本文链接:

https://wiki.ohiyox.in/archives/17/
1 + 5 =
快来做第一个评论的人吧~