Site logo

Archived topic

Is there a way to do post navigation but within a specific category?

7 replies · Started by Arp on March 10, 2022

Viewing posts 1–8 of 8

I know how to do overall post navigation for all blog posts, but I'm trying to figure out if it's possible to navigation but limit it to posts in the same category.

Say my blog has two categories: Home & Work.

On Home posts, the prev/next post navigation links would go to either the previous post in the Home category, or the next post in the Home category.

On Work posts, the prev/next post navigation links would go to either the previous post in the Work category, or the next post in the Work category.

Doable?

Thank you! Will that snippet make all post navigation across site be within categories? Or could it be confined to specific categories?

It will apply to all posts.

I could probably live with that. Or maybe figure out some php for 'if category = X then use this function.'

Thanks!

You can try something like this:

add_action('wp', 'custom_generate_category_post_navigation');
function custom_generate_category_post_navigation() {
	 if (in_category('cat-x')) {
	    add_filter('generate_category_post_navigation', '__return_true' );
   }
}

Replace the cat-xwith your category slug.

Thank you, you are too kind!

No problem :)

Glad to help!

This archived topic is closed to new replies.