How to Exclude Category Posts from your Wordpress Homepage
I recently updated my template for my blog (thank you Joern Kretzschmar) and started using Wordpress’ bookmarklet feature to post quick news from sites I like to visit. I didn’t want these bookmarklet posts to show up on my homepage and here is a really simple way to accomplish it. If you’re not technical, don’t worry, it’s really simple.
Here’s how to do it:
1) Edit the index.php file in your theme folder (or edit it from Presentation -> Themes)
2) find the category ID of the category you want to exclude from Manage -> Categories
3) crack open index.php in the root of your theme folder.
4) About 20 lines down there is some code:
<?php while (have_posts()) : the_post(); ?>
change it to this:
<?php while (have_posts()) : the_post(); if (is_home()) if (in_category(’YOUR-CATEGORY-ID’)) continue; ?>
Props to Blogulate for the tip.
Related posts:
August 15th, 2008 at 3:18 pm
It doesn’t work with version 2.6.1 .
August 16th, 2008 at 12:49 pm
Right, I’ve only used it on 2.3. I think 2.5 and higher has something built in to handle this type of thing, but I’ll check.
August 17th, 2008 at 1:04 pm
Hi, thanks for this piece of code, but can you write this one once again for 2.6.1? I think I’m not only the one, which will appreciate it:).
August 17th, 2008 at 1:09 pm
Hmm, it seems I figured it out. Try this:
August 17th, 2008 at 1:14 pm
Hmm, it seems I figured it out. Try this: <?while (have_posts()) : the_post(); if (in_category(’’YOUR-CATEGORY-ID’’) && !is_single() ) continue; ?> I found it here
October 9th, 2008 at 7:11 pm
It works for me in 2.6.1.
February 8th, 2009 at 11:23 am
hi there…
your original code seems to work fine in the new 2.7, but the updated code that you put in the comments doesn’t (page goes blank)…
seems you were right from the start…
March 3rd, 2009 at 12:24 am
Thanx! your original code worked fine! I used it on my Archives page to separate the portfolio content form the blog posts!
Thanx again!
April 1st, 2009 at 8:28 pm
Doesn’t work in 2.7.1 in my case, i wan’t to exclude category 966 and i have this code.