HTML5 Zone is brought to you in partnership with:

Paulund is a website dedicated to writing tutorials and code snippets about Web Development, the main subjects are PHP, Wordpress, jQuery, CSS3 and HTML5. Paul is a DZone MVB and is not an employee of DZone and has posted 134 posts at DZone. You can read more from them at their website. View Full User Profile

Add Category RSS Feed Link

12.27.2012
| 2063 views |
  • submit to reddit

 

When you have a WordPress site you can assign different posts to categories, this allows you to group your posts together.

For example on this site I have created categories for tutorials and snippets, so if people are looking to create a complete feature you can look in the tutorials category, but if you just want some useful coding tips you can just in the snippets section.

When you create a category you are then able to navigate to this category to view all the posts which are grouped in the category.

When you view a certain category WordPress will display this content using a number of files, which are displayed in the category hierarchy of:

  • category-slug.php
  • category-ID.php
  • category.php
  • archive.php
  • index.php

First WordPress will check to see if you have a file in your theme folder names category-{category-slug}.php, if this exists then it will use this to display your category content. If this doesn't exist then it will search for a file called category-{ID}.php, then category.php, then archive.php, the finally the index.php.

I normally create a category.php file to show the category content useless I want a certain category to look different than all the others.

Add A Category Feed For Certain Category


There maybe some categories which are more popular than others, for example you might have a freebie category where you post about free products on each post. This is a perfect candidate for someone to subscribe to just this category RSS feed.

Luckily in WordPress it will create an RSS feed for each category and they make it very easy to create a link to this RSS feed.

First open up your category.php file and add the following code to the top of your content.

<?php
     $category = get_category();
?>
<a href="<?php echo get_category_feed_link( $category[0]->cat_ID ); ?>">Subscribe to the <?php echo $category[0]->name; ?> category RSS feed</a>
Published at DZone with permission of Paul Underwood, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)