Excluding Categories from Your WordPress RSS Feed

Filed under: Web Development,Wordpress — Tags: , , , — Chris @ 7:45 pm

As a supplement to my previous post about having a separate template for a specific category I thought I should let you know how I excluded a category from a RSS feed.

Say you have a news category that looks different and says something different than the rest of your blog, you might want to exclude that from your RSS feed. I found the following code at WPRecipes (which is down at the time of this writing):

function myFilter($query) {
if ($query->is_feed) {
$query->set('cat','-5'); //Don't forget to change the category ID to what you want
return $query;


Place this in your functions.php file. I’m not sure if you can exclude more than one, but my guess is you can just add more category IDs and seperate them with commas: $query->set(‘cat’,'-5,-10,-11′);

Use Different Single Post Templates for Different Categories in WordPress

Filed under: Web Development,Wordpress — Tags: , , — Chris @ 7:35 pm

I recently had to figure out how to use a separate post template for a specific category like you can with pages in wordpress. I found a solution at nathanrice.net.

Just add the following code to you functions.php file:

<?php add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' )); ?>

Then all you have to do is create a new single post template and name it “single-X.php” where “X” is the category ID of your choice.

If you have multiple categories assigned to a single post and they both have special templates you’ll run in to problems. This code will select the template of the category with the largest number.