Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @wahine555!
    It can be done easy.
    Put this to you function.php

    function exclude_category($query) {
    if ( $query->is_home() ) {
    $query->set('cat', '-XXX');
    }
    return $query;
    }

    replace XXX with the number of the category you want to exclude.
    For example, to exclude BABY you use 625.

    Keep in mind that you have to do in the child theme

    To remove Archives, in you wordpress Dashboard go Appearance -> Widgets and delete widget Archives from the sidebar.

    Thread Starter wahine555

    (@wahine555)

    Thanks @dmytro, I’ll try that.

    I’d like to leave the archive widget, I’d like like a particular category to not return results in the archives… For example, Month:October would pull all October posts but not including the BABY category.

    It should be possible too.
    Try to add this to your archive.php (in the child theme):
    <?php query_posts('cat=-1,-2,-3');?>
    where 1,2,3 are the category numbers to exclude.
    Put this code just before the loop <?php if ( have_posts() ) : ?>

    Thread Starter wahine555

    (@wahine555)

    @dmytro Thank you sooo much! I played with what you gave me and I think I’ve come up with something that works for my child theme. The other thing I noticed is now I need something to remove it from the “previous” and “next” post links :/

    function exclude_category( $query ) {
    if ( $query->is_home() || is_archive() && $query->is_main_query() ) {
    $query->set( ‘cat’, ‘-636’ );
    }
    }
    add_action( ‘pre_get_posts’, ‘exclude_category’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding Category in blog post view’ is closed to new replies.