Archived topic
Exclude category or specific posts from related posts
16 replies · Started by Olaniyi on September 16, 2020
Hi, How can I exclude multiple posts or a category from the related posts section; <nav id="nav-below" class="post-navigation">
https://www.dropbox.com/s/42u60ovytfp64gm/2020-09-16%2016_15_31-Window.png?dl=0
Hi there,
Would something like this help?
https://docs.generatepress.com/article/generate_category_post_navigation/
Yes, it should solve the problem.
Glad to hear :)
Hi, Can you help with a sample code, struggling to solve it by myself.
Try this:
add_filter( 'generate_category_post_navigation', '__return_true' );
Adding PHP: https://docs.generatepress.com/article/adding-php/
I got this part, the code I was asking for:
If I want this to work for a specific category rather than the whole website.
Try this:
add_action( 'wp', 'lh_category_navigation' );
function lh_category_navigation() {
if ( is_category( 'CATEGORY NAME' ) ) {
add_filter( 'generate_category_post_navigation', '__return_true' );
}
}
https://codex.wordpress.org/Conditional_Tags#A_Category_Page
This works, Thanks!
No problem :)
Hello, Is it possible to prevent some specific posts from showing in the post navigation? For example, if I have some posts unsuitable for kids, and I don't want them to show under any post navigation, how would I exclude these posts?
Hi,
Consider creating an R-18 category for posts that are not suitable for kids/minors.
You can then exclude that R-18 category the same way you've excluded the other categories.
Yeah, that would work but it is not ideal in the current situation, which is why I reopened the topic.
Is there any post specific situation, maybe excluding with post ID, something like that?
It's pretty complicated to modify the WordPress posts loop like that.
A plugin like WP Show Posts should help:
https://en-ca.wordpress.org/plugins/wp-show-posts/
Then you can use the exclusion option:
https://docs.wpshowposts.com/article/more-settings-overview/#exclude-post-ids
Alright, I will keep at it, thanks.