Exclude Categories From Home Page

It would seem logical that you would want to exclude some categories posts from showing up in your main blog or home page, WordPress however by default  will show all posts from all categories in the main blog page making your main blog a mix of all sorts, if you would like to overcome this the solution below is the best if have found.

In your index.php you will see some code like this:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
(Stuff that displays the posts)
<?php endwhile; ?>
<?php else : ?>
(Stuff to show if no posts were found)
<?php endif; ?>

To exclude categories you need to tell WordPress before all of that what to exclude:

<?php
if (is_home()) {
$page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
query_posts(“paged=$page&cat=-1,-2,-3”);
}
?>

This will exclude categories 1,2,3

Posted in All Things Wordpress, Off Topic.

Leave a Reply

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