WordPress TwentyTen Tip: Show posts from a certain category on the homepage

Go to Appearance > Editor and edit ‘loop.php‘.

Just under

/* Start the Loop.
*
* In Twenty Ten we use the same loop in multiple contexts.
* It is broken into three main parts: when we're displaying
* posts that are in the gallery category, when we're displaying
* posts in the asides category, and finally all other posts.
*
* Additionally, we sometimes check for whether we are on an
* archive page, a search page, etc., allowing for small differences
* in the loop on each template without actually duplicating
* the rest of the loop that is shared.
*
* Without further ado, the loop:
*/ ?>

replace following bit of code

<?php while ( have_posts() ) : the_post(); ?>

with

<?php if ( is_home() ) { query_posts($query_string . '&cat=-5'); } ?>

Notice the ‘=-5‘ this tells the homepage not to display posts from the post category id ’5′.

If you want to stop more than one category from being displayed just separate with a comma and write ,-# , where # is the id number of the category – see below.

<?php if ( is_home() ) { query_posts($query_string . '&cat=-5,-3'); } ?>

To revert back to showing posts from all categories just change it back to

<?php if ( is_home() ) { query_posts($query_string . '&cat'); } ?>
This entry was posted in Web Tips & News. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


- 4 = one

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>