Excluding a particular category posts from home page
January 12, 2009 · Article by Sriraj · Leave a Comment
If you’re using wordpress you may sometimes need to keep a particular category away from appearing on your homepage.This situation arises when you start a category and post few posts in it and eventually they get indexed and later you realise that the category is not relevant to your blog topic and decide not to post any more topics under that category.
Well you can do that,but you can still be able to post under that category and make them not appear in you home page.
I know how to do this but wanted to find out if any plugin existed for this.I didn’t find a plugin but I certainly did find a method to do this.
Vandaley posted few category related hacks which I thought I might use .
But there was a trouble in using his method (Better Once visit his blog and come back to understand this).
When I added <?php query_posts(‘cat=-4′); ?> to the existing <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> code in my template.The category which I wanted to exclude has been excluded successfully.But there was a problem.
When I clicked on that category as whole,posts under different categories turned up.Even tha tags under that category didn’t work.
Hence it was not the perfect method for me.Using the simple loop instructions given at wordpress codex you can solve your problem.
Just go to your main index template and place
<?php if (in_category(‘13′) && is_home() ) continue; ?> under <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
We are simply giving a instruction that when the category 13 turns up,we leave it behind and continue to next post to show up in home page.
Where 13 represents your category ID.I suppose you know hot to find out your category ID’s? Now save your changes and see whether you are done or not.I think this should do it.
Note that eventhough the post doesn’t appear in homepage wordpress bot will still be able to access it as usual and I suppose Google does the same.Should wait and see in the latter case.
