1
votes

I'm looking for a function to return/ouput the link to the next and/or previous post in the same SUBcategory.

Using the previous_post_link() function it will only take into account the parent-category.

The structure of the categories is something like this:

  • Work
    • Graphic Design
    • Webdesign
    • Layout
    • Illustratie
    • Packaging
    • Fotografie

So when I am on the single page of for example a webdesign-post I want links to other articles inside the webdesign subcategory. For now the next/previous_post_link() function just returns the next/previous link to a post inside WORK

Do any of you have a good solution for this? Plugin/custom code/....?

EDIT

I've found the solution to this one. I've tried building around it in the way that Boris suggested, but that didn't work for me. And then I found that I should just not add the parent-category in the edit page. Weird as it may be, this did the trick. Just add the child-category and it will be still pullen on page when you want all posts of the parent-category. But when using the previous_post_link()/next_post_link() it will just use the child-category!

1

1 Answers

0
votes

You can define filters: get_previous_post_join & get_next_post_join and alter the JOIN clause for the get_adjacent_post() function. Look at line 1111 to 1115 in wp-includes/link-template.php (WP 3.3.0). If, in your filter callback, you get the IDs of "Work" and subcategories and alter the tt.term_id IN (...) part then I believe you will be able to get the desired links.