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 - 9 votes

Written by: on September 6, 2012. Last modified: September 7, 2012

Popular Marketplace Items

  • dear-seven-responsive-multipurpose-theme-thumbnail
    $39

    Envelope

     (1)
    A responsive multi-purpose WordPress theme for business or personal portfolio.
  • daddy-likes-190x130
    $19

    Daddy Like

     (10)
    A fast, lightweight, and elegant "like" system for comments, pages, posts, & activities.
  • pcp-featured
    $39

    Price Comparer

     (3)
    Jump start your Price Comparision site with products from Amazon, Commission Junction, and LinkShare.
  • thumbnail-vantage-image-slider
    $19

    Image Slider for Vantage

     (2)
    Replace the Vantage listing and events gallery with an image slider.
  • StarStruck WordPress Plugin Thumbnail
    $19

    StarStruck

     (14)
    A fast, lightweight, and elegant star rating system for comments, pages, & posts.
  • thumbnail
    $29

    Ad Injector

     (3)
    Inject adverts directly into listings and search results. Works with multiple themes.
  • critic-icon-2
    $39

    Critic

     (6)
    A professional review and rating system for WordPress.
  • dear-seven-responsive-multipurpose-theme-thumbnail
    $39

    Creative

     (2)
    A responsive multi-purpose WordPress theme for business or personal portfolio.
  • autoauto-thumbnail
    $39

    AutoResponder AutoRegistration

     (4)
    Automatically integrates WordPress registration with major autoresponders.
  • Ad Stuffer for Jobroller by Appthemes
    $19

    Ad Stuffer JobRoller

     (1)
    Stuff your JobRoller Theme with 14 extra Ads & Links!
  • GeoReg thumbnail
    $29

    GeoReg

     (10)
    Captures detailed geographic info with new user registrations.
  • featured
    $9

    QR Codes Widget

     (3)
    Add a widget with QR codes to your AppThemes site.
  • thumbnail-vantage-user-locator
    $19

    User Locator for Vantage

     (7)
    Auto-detect & add your visitors location using geo coordinates.
  • adposter-blocker-thumbnail
    $9

    AdPoster Blocker

     (2)
    A simple but powerful plugin that blocks spammy new user regs and/or ads/jobs/posts.