• Resolved doubledown11

    (@doubledown11)


    Hi, I have tried several methods, including adjusting the functions.php file and adding an if is_home, cat (8) approach to exclude my category from appearing in the front page, but no luck.

    I don’t want to use a plug-in. I’d like to just code in to my index.php or my functions.php not to include category 8 posts on the front page.

    Here is the functions code:

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

    Please help me out.

    Thanks
    DD

Viewing 5 replies - 1 through 5 (of 5 total)
  • i dont think that this [spam link moderated]
    is the same but maybe this will help you.

    Good luck

    query_posts=($query_string . '&cat=-8');
    Thread Starter doubledown11

    (@doubledown11)

    MichaelH, can you please tell me where to enter that code you’ve provided?

    Thread Starter doubledown11

    (@doubledown11)

    This worked for me:

    Next, go into Appearance > Editor, and open functions.php. Add the following function:
    function exclude_category($query) {
    if ( $query->is_home ) {
    $query->set('cat', '-xx');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    where xx is the number of your category. Don't forget the minus sign in front of it! Save it, and you're done.
    Gouri

    (@gouri)

    inserting this:
    <?php query_posts($query_string . ‘&cat=-32’); ?>
    just before:
    <?php if (have_posts()) : ?>
    worked for me.
    But somewhere in the codex, I read that it will exclude this particular category posts from category archive also (if we don’t have a separate template for category). I don’t see any separate category template in my theme files. Even the, I am not having any such problem.
    Will it have any other ‘side effect’?
    Following is not working for me:
    <?php
    if (is_home()) {
    query_posts(“cat=-3”);
    }
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to Exclude a Category From Front Page’ is closed to new replies.