Hi,
On archive pages, you can set standard pagination or infinite scroll. For the next and previous pagination styles, you have to add custom code. On a single post or page, you can see the next or previous post/page option. Let me know if I didn’t understand your query clearly.
Hi Amid
Thanks for the response. What I want to achive is the following explanation:
I select a category and get all posts relatet to that category as a list.
Then I select one post and get the post as a single post with previous/next arrows with other posts
these other posts don’t stay in the specific category.
Hi,
Kindly go to Customize > Blog > Single Post > Single Post Options and select Category from Next/Prev Post Taxonomy settings.
This will make the pagination as you want.
Hi,
It is because your current post fall into both categories, therefore it is showing posts from both categories.
Hi Amit
would it be possible to navigate only within the primary category. This would solve my issue.
Hi,
You can try the below code. Try it on a staging site and take site backup before that. You can add code using child theme.
function prefix_parent_category_navigation( $where, $in_same_term ) {
if ( ! is_singular( 'post' ) ) {
return $where;
}
if ( ! $in_same_term ) {
return $where;
}
$categories = get_the_category();
if ( empty( $categories ) ) {
return $where;
}
$cat = $categories[0];
while ( $cat->parent != 0 ) {
$cat = get_category( $cat->parent );
}
$parent_id = $cat->term_id;
global $wpdb;
$where .= $wpdb->prepare(
" AND tt.term_id = %d ",
$parent_id
);
return $where;
}
add_filter( 'get_previous_post_where', 'prefix_parent_category_navigation', 10, 2 );
add_filter( 'get_next_post_where', 'prefix_parent_category_navigation', 10, 2 );
Hi Amit
thank you very much. I will test it.