[Resolved] Exclude category or specific posts from related posts

Home Forums Support [Resolved] Exclude category or specific posts from related posts

Home Forums Support Exclude category or specific posts from related posts

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1445939
    Olaniyi

    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

    #1445960
    Leo
    Staff
    Customer Support
    #1445967
    Olaniyi

    Yes, it should solve the problem.

    #1445969
    Leo
    Staff
    Customer Support

    Glad to hear ๐Ÿ™‚

    #1446024
    Olaniyi

    Hi, Can you help with a sample code, struggling to solve it by myself.

    #1446032
    Leo
    Staff
    Customer Support

    Try this:
    add_filter( 'generate_category_post_navigation', '__return_true' );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1446036
    Olaniyi

    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.

    #1446044
    Leo
    Staff
    Customer Support

    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

    #1446055
    Olaniyi

    This works, Thanks!

    #1446063
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #1449213
    Olaniyi

    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?

    #1449229
    Elvin
    Staff
    Customer Support

    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.

    #1449257
    Olaniyi

    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?

    #1449264
    Leo
    Staff
    Customer Support

    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

    #1449276
    Olaniyi

    Alright, I will keep at it, thanks.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.