Exclude category from Recent Posts

Home Forums WordPress Theme Support BresponZive Mag Exclude category from Recent Posts

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3495
    Geomenezes
    Member

    Hello.

    Is there any – easy – way to exclude a certain category of the recent posts widget of the Bresponzive mag theme?

    I’ve tried several plugins, fixes and other workarounds, but none of them was good enough – sometimes not showing the thumbnails, with different typography and styling, etc.

    Once I’ve got a homepage single widget of this category right after the recent posts widget, I would like to remove those posts from the recent posts widget.

    I can send my site details if you wish.

    Thanks in advance!

    #3498
    Raja CRN
    Keymaster

    Hi,

    Do you want to exclude the categories from the Recent Posts Section? If that so, It’s not a widget, It’s a WP main content section. You can’t exclude the cat ID in the main loop, instead of that you have to create custom queries to achieve the desired result.

    You can get the sample query in page-blog.php in our theme. In that query, you have to pass the cat=-12 here -12 is your category ID.

    or easy way, include the following code in functions.php and add the category ID to be excluded.

    function tp_exclude_category( $wp_query ) {
    
        // Add the category to an array of excluded categories. Here, We pass the -1 as a category ID, 
        
        $excluded = array( '-1' );
    
        // Note that this is a cleaner way to write: $wp_query->set('category__not_in', $excluded);
        set_query_var( 'category__not_in', $excluded );
    
    }
    add_action( 'pre_get_posts', 'tp_exclude_category' );
    

    I think, i got your question. If that doesn’t solve your question, reply to us.

    Thank you.

    #3510
    Geomenezes
    Member

    Yes, you’ve got my question, thanks.

    When I mentioned I tried some widgets, I was talking about a recent post widget in which I could select the post categories I want to show, or hide.

    Great code, but this affects only the archive.php page, right?

    About the recent posts theme pacific widget, in the homepage or index, do you have any code that could help with what I asked for?

    Thanks again.

Viewing 3 posts - 1 through 3 (of 3 total)

Only Verified Customer of this Theme Can post reply to this Support Topic! .