- This topic has 7 replies, 2 voices, and was last updated 5 years, 8 months ago by Tom.
-
AuthorPosts
-
July 15, 2018 at 5:01 pm #624458JANEK
Good morning,
I just noticed that the post navigation that appears on single posts is not limited to the the posts category so will pick up everything. Is there a way to limit the post navigation to their respective category? Or will it be a case of just having to tell the post navigation to exclude certain categories I dont want displayed?
July 15, 2018 at 9:12 pm #624532TomLead DeveloperLead DeveloperThere’s a filter for that!
add_filter( 'generate_category_post_navigation', '__return_true' );
That should do it π
July 15, 2018 at 9:21 pm #624538JANEKAwesome, is there a way to make this function only on the Post type. Rather than everything. I have a custom post type that I’d like to retain the original functionality on, but on my default Post type I just want it to navigate its respective categories.
July 16, 2018 at 9:39 am #625008TomLead DeveloperLead DeveloperYou could try:
add_action( 'wp', 'tu_cpt_cat_specific_links' ); function tu_cpt_cat_specific_links() { if ( is_singular( 'your-post-type' ) ) { add_filter( 'generate_category_post_navigation', '__return_true' ); } }
July 16, 2018 at 4:45 pm #625230JANEKDone and dusted! That was easy. Thank you! π
July 16, 2018 at 9:09 pm #625311TomLead DeveloperLead DeveloperYou’re welcome π
July 29, 2018 at 11:57 pm #635713JANEKHey Tom,
Sorry to dredge this one up, it seems to not work on custom post types. For example I’m using the Seriously Simple Podcast plugin and its added a custom post type named ‘podcast’ to the site. However I dont think the podcast CPT uses the name categories which your code refers to but rather it uses a custom taxonomy which they’ve called ‘series’. Would you be able to assist me in modifying your code to work with the new taxonomy and CPT name?
To give you an idea of what I’m trying to achieve… I have two series (categories) one is the main podcast series the other is titled next episode, and I want to keep the next episode out of the post navigation essentially. If that makes sense.
Your login is still valid for the site if you want to take a look at how the podcast series are setup.
The site url is:
http://staging.janek-dev.flywheelsites.com/July 30, 2018 at 10:02 am #636253TomLead DeveloperLead DeveloperYea, the taxonomy being different will mess it up.
I’m not 100% sure, but you could try this:
add_filter( 'get_next_post_join', 'tu_adjust_taxonomy_links' ); add_filter( 'get_previous_post_join', 'tu_adjust_taxonomy_links' ); function tu_adjust_taxonomy_links( $join, $in_same_term, $excluded_terms, $taxonomy ) { if ( ! is_singular( 'podcast' ) ) { return $join; } $taxonomy = 'series'; return $join; }
-
AuthorPosts
- You must be logged in to reply to this topic.