Monday, March 22, 2010

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.

Visitors who read this article also read:

  1. Show different posts per pageSetting your blog’s home page to show only excerpts of your posts looks good as it gives your visitors a...
  2. Wordpress stats plugin now shows home page views tooWhat I noticed today when I went to the site stats section is that the Wordpress stats plugin is showing...
  3. Home page excerpts in bloggerHome page excerpts gives your audience a brief view about a bunch of your posts at once and if they...
  4. Have a good blog title, improve your SERP resultsA title for your homepage should invariably describe the whole of your blog in a sentence. It’s the descriptive part...
  5. Get rid of dynamic characters (?,=,_) from your permalinkIf your using wordpress for your blog one thing to notice is the permalink structure. It is always better to...
  6. Fatal error:call to undefined function wp_get_current_user(); in line 920You probably might have got the above error and hence are here.Ok lets see what to do now. I uploaded...

Have something to say?

Tell us what you're thinking...

Have your own website

Sriraj Digital Magazine on Mobile

Now you can have all the latest updates while you are on the go too. Just visit our website www.sriraj.org from your mobile and stay updated. The content is especially formatted for touch devices, but I promise, other mobile users won't be disappointed too.
Note: If you are being taken to the normal website when visiting through your mobile, please let me know your mobile make and its user-agent (like Nokia6300, for example)