How to Create WordPress Category RSS Feeds

WordPress RSS Shop

Here’s a fun fact I bet you didn’t know: WordPress provides built-in feeds for every category, tag, comment, post, author, and even search result.

The problem is, how do WordPress users know where the feeds are and how to utilize them? Well, unless your theme already has this setup, you really don’t. This tutorial will show you how to dynamically create and display WordPress category-specific feed icons.

Why are category-specific feeds important?

Some people aren’t interested in a general rss feed. They want to follow a specific category. For example, our new Marketplace includes several different categories (i.e. Child Themes, Plugins, Payment Gateways, etc).

If you’re interested in all new items, you can subscribe to the general rss feed. On the other hand, say you only care about new payment gateways and don’t want your AppThemes rss feed cluttered up with new child theme items.

Step 1 – Add one cup code

Edit your category.php theme file and paste in the following code somewhere towards the top. This will display the feed link. If you don’t have category.php, you’ll either need to create it (advanced users) or edit your archive.php template which is the fall thru template.

<?php
if ( is_category() ) {
  // retrieve current category object
  $category = get_category( get_query_var('cat') );
  if ( ! empty( $category ) )
    echo '<div class="category-feed"><a href="' . get_category_feed_link( $category->cat_ID ) . '" title="' . sprintf( __( 'Subscribe to the &quot;%1$s&quot; category', 'appthemes' ), $category->name ) . '" rel="nofollow">Subscribe!</a></div>';
}
?>

You’ll notice we did a couple of things. First, get the current category object. Then grab the feed link using get_category_feed_link(). We also added a title tag which is useful when hovering over an icon (instead of using text) and a rel="nofollow" so we don’t leak SEO juice.

Note: We wrapped an extra if is_category() check around the code so it would work in archive.php.

Step 2 – Test it out

Visit any of your category pages and you should see a “Subscribe!” link. If you hover over the link, you’ll notice it’s unique for the category. Great! You’ve got it working now. Next, we need to pretty it up.

Step 3 – Put on some makeup

We wrapped the link with a div so it’s easy to style the link. If you want to use just an icon instead of the text link like we did, you can do that too. Just remove the “Subscribe!” text from the code and include an rss icon in the css. You will paste this in your theme’s style.css file. Here’s what we used:

.category-desc { 
    margin-bottom:10px; 
}
.category-feed a { 
    float:right; 
    width:16px; 
    height:16px; 
    background:url('images/rss-icon.png') no-repeat left 0 transparent; 
}
.category-feed a:hover { 
    opacity:0.7; 
}

You’ll likely need to make some tweaks before it’s perfect but that’s pretty much it!

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 3.6 - 15 votes

Popular Add-ons

Logic Widgets for Vantage

Quickly and easily add conditional content to your Vantage site including…


(4)
$29

A-Z Business Listing

Inserts an A to Z listing of Business's for Vantage


(5)
$19

AppThemes Coupons

Start offering coupons and promotions to your customers.


(15)
$29