Today I figured I would create a category that doesn’t appear on my main page, for testing out some ideas. So I searched google, as I usually would, for instructions to do this.
As usual, answers were forthcoming from the WordPress site itself. It was as simple as modifying index.php for the theme I use, and adding a line so The Loop skipped execution of the main body of the loop, if a category matched the exclusion. Fair enough.
But then I discovered that posts from the excluded category appeared in my rss feed. Not good. After much research, I found many posts from people wanting to know how to do this, but hardly any useful information.
It turns out it is quite simple to exclude a category from an rss feed – it’s done in much the same way as for the main page – editing The Loop. Only in this case, The Loop can be found buried in wp-includes/feed-rss2.php (and also feed-atom.php, feed-rdf.php, and feed-rss.php). Search for the line
<?php while( have_posts()) : the_post(); ?>
and directly after it, insert
<?php if (in_category(‘3’)) continue; ?>
if you want to exclude category id 3. Simple!
August 16, 2008 at 3:31 am
Hi, I tried your solution. It broke my RSS feed, have you tried this with the latest version of WordPress?
August 20, 2008 at 11:13 am
I haven’t changed anything since I upgraded to 2.6, but I was only excluding one category and I haven’t written a post in that category for ages.
September 2, 2008 at 2:50 pm
Hmm… The problem seems to have worked itself out, not sure what was wrong in the end. Thanks for the response though.