Displaying WordPress Category RSS Feed Link

November 15, 2008 · Print This Article

Here is the function that controls the feed link of category as globally set by WordPress:

<?php
get_category_feed_link($cat_id,$feed)
?>

Basically it returns the category feed link. $cat_id is the category id. $feed should be replaced with feed name. Most probably you can use something like this:


<?php
get_category_feed_link('14','');
?>

That function tells wordpress to return feed link for category with ID 14 and default feed name RSS 2.

Ok that is good progress. But it will not print the results to browser until we print it like that:


<?php
print get_category_feed_link('14','');
?>

This will return feed link for category 14 regardless of permalink structure.

Practical use
Let us step in final stage. We need practical use for this function. A very common use is that you may want to display category RSS feed links besides category title when you are viewing a category.

1. Open category.php then add this code where you wish to display the category RSS feed link…

<?php
$this_category = get_category($cat);// This line just gets the active category information
print '<a href="'.get_category_feed_link($this_category->cat_ID, '').'">Subscribe</a>';
?>

The second line displays a link with anchor “Subscribe”. We used our get_category_feed_link() function but instead of assigning ID we let it discover the category ID automatically. So it will display the proper RSS feed link for any displayed categoy in category.php template.


Your choice for site templates and wordpress themes

Comments

2 Responses to “Displaying WordPress Category RSS Feed Link”

  1. AndyiBM on May 2nd, 2009 7:03 pm

    Thanks for this – after I realised I had a Feedburner plugin activated on one of our sites that was preventing a feed to a specific category, I managed to get it working.

    I have RSS feeds listed on my iGoogle homepage. The header states the category name, but clicking this directly takes me to the homepage of the site, not the category page. Is there a way of getting this to link correctly?

  2. Why does it have to be so hard??? Part V The Nexuss Point on April 23rd, 2011 7:18 pm

    […] much gnashing of teeth, I found this site http://www.livexp.net/wordpress/displaying-wordpress-category-rss-feed-link.html.  It was quick work from […]

Got something to say?

You must be logged in to post a comment.