Single Category RSS feed in WordPress

rssiconSo now having installed WordPress, it turns out that it is infinitely customisable! Oh joy… more to learn about!

The task was to be able to build a single category RSS feed that people can subscribe to if they so chose, rather than have to subscribe to all categories, or all comments. In the theme I am using the sidebar holds the category list and it was here that the code had to go.

The issue was to find the category ID and the category name and only show the link to the RSS *if* the user had opted to view all posts in a single category.

It turns out that WordPress has done most of the hard work for us, in that the functions to get the ID and name are already created. All that had to happen was to find those arguments, wrap them in an ‘If’ tag and post them to the sidebar. Once again, some gentle reading of the Woprdpress documentation got me half way there and able to manually write the code for each category… but it needed automating. And once more, Alex Blanc stepped up to the plate…

To cut a very long story short, here’s the code, entered as a list item in the sidebar.php file for the theme:

<?php if (get_query_var('cat')) { ?>
<li>
<a xhref="/wp-rss2.php?cat=<?php echo get_query_var('cat'); ?>"><?php echo single_cat_title(); ?> (RSS)</a>
</li>
<?php } ?>

This then writes the title of the category in the sidebar as an RSS link, and ensures that only that category’s posts are included in that particular feed. You can see from the code that the link is using RSS2, so you can probably amend this to be any other flavour of feed that you wish.

6 thoughts on “Single Category RSS feed in WordPress

  • 29 November, 2006 at 10:18 am
    Permalink

    Problem with RSS Feed in WordPress.
    I have a subdomain that I installed wordpress for another blog site, but the subdomain site's rss feed points to my parent site.
    Can anyone come up with any suggestions?

  • 29 November, 2006 at 11:28 pm
    Permalink

    Sorry Quentin – I’m probably not the person to ask… but head over to alex’s blog… he will be able to help, I’m sure.

  • 12 September, 2008 at 12:59 pm
    Permalink

    I tried adding the code to the sidebar of my blog

    it worked up to a point – i.e. it did nothing on the home page but did include a line on the category pages – so that part works OK

    but it only made the line text – not an actual live hyperlink – there seems to be an error in the syntax of the code – do you have the correct code that will make the link live?

  • 12 September, 2008 at 1:45 pm
    Permalink

    Hi,

    I got the link live by changing

    <a xhref=”/wp-rss2.php?cat=
    to
    <a href=”/wp-rss2.php?cat=

    unfortunately I still can’t use it as it brings up a page like http://www.tradercurrencies.com/wp-rss2.php?cat=45 and I have search friendly urls so it causes an error page to show instead of the category page url

Comments are closed.