Support » Fixing WordPress » Excluding a category from Recent Entries

Viewing 6 replies - 1 through 6 (of 6 total)
  • Might check The Loop article out as there’s a section on how to exclude a category.

    I do something very like what you want. I have one regular blog page and one ‘News Items’ page which just has posts in the category NewsItems. So I exclude the NewsItem category from the regular blog page by having this code in my index.php.

    <?php   get_header(); ?>
    
    // leave out category 'NewsItems' from the Blog (i.e. 'home' page)
    <?php if ( is_home() ) {
            $newsCatID= get_cat_id('NewsItems');
            query_posts($query_string . '&cat=-' .$newsCatID);
    }
    ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    The query_posts call causes the unwanted cat to be filtered out of the have_posts result set. The nice thing about doing it this way is you don’t have to hard-code a cat ID into the PHP.

    Thread Starter agentmanningctu

    (@agentmanningctu)

    I can’t figure out how to tweak that to fit my blog. Which settings would I need to change?

    Thread Starter agentmanningctu

    (@agentmanningctu)

    jvector?

    Can anyone else tell me where I would put that bit of code?

    Thread Starter agentmanningctu

    (@agentmanningctu)

    Can anyone help?

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    That’s “the loop”. It’s in your index.php of your theme. So is this:

    <?php get_header(); ?>

    So the rest goes in between I guess.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Excluding a category from Recent Entries’ is closed to new replies.