How to keep prevnext nav on posts in same taxonomy

admin2025-01-07  4

I am using a theme called Avada a fairly well known theme. By default wordpress if you have more than one category for posts and have prev/next nav on for the posts wordpress will run thru all the posts and not keep them in same taxonomy. I figured code for another theme to make the prev/next stay in the same taxonomy but am having trouble making this work. Does anyone have some code for the functions php or single post php that would achieve this for wordpress in general? They're used to be a plugin for this but it's way out date. Thanks.

I am using a theme called Avada a fairly well known theme. By default wordpress if you have more than one category for posts and have prev/next nav on for the posts wordpress will run thru all the posts and not keep them in same taxonomy. I figured code for another theme to make the prev/next stay in the same taxonomy but am having trouble making this work. Does anyone have some code for the functions php or single post php that would achieve this for wordpress in general? They're used to be a plugin for this but it's way out date. Thanks.

Share Improve this question asked Dec 7, 2024 at 17:20 tonyitonyi 11 bronze badge 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Dec 11, 2024 at 23:24
Add a comment  | 

1 Answer 1

Reset to default 0

There's a decent stack of functions here:

  1. next_post_link()
  2. get_next_post_link()
  3. get_adjacent_post_link()
  4. get_adjacent_post()

Unfortunately, within this stack of functions, there aren't any filters that are intended to change the $in_same_term parameter.

Probably the best approach would be to create a child theme and override the single.php file within the child theme, and change the parameters of next_post_link() and previous_post_link() to set the $in_same_term parameter to true.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736262493a822.html

最新回复(0)