Exclude categories from Blog - by Olexi - on WordPress WooCommerce support

This topic has 2 replies, 2 voices, and was last updated 5 years, 8 months ago ago by Rose Tyler

  • Avatar: Olexi
    Olexi
    Participant
    April 15, 2019 at 12:19

    Hi, we want to exclude some post categories from the “standard” blog page. They should be shown on a different page with a post-grid element.

    How can we exclude them? Did not find an option in the xstore theme options?

    Also it would be great to show a categories filter on top of the blog page instead of the one in the sidebar (because of mobile)

    Many thanks.

    1 Answer
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 15, 2019 at 12:32

    Hello,

    1) There is no such option by default.
    You can use code like this

    function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'cat', '-1' );
    }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    in functions.php of child-theme.
    Don’t forget to replace the ID number in the code with the actual ID number of the category you need to remove (in our example the ID number is “1”, “-“ tells us that the category should be excluded).
    2) Theme Options > Blog > Blog layout > Sidebar position for mobile.

    Regards

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.