Snippet: Subscribe to category’s RSS feed

On my urban planning blog, Steven can plan, I wanted to add a link the category’s RSS feed when the category page is viewed. Here’s the code for that.

In your theme’s index.php page, insert this code inside the IF(is_category) statement:


// get the current Category so we can get ID and Name
if (is_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
}

// Build the output values
$name = $cat->cat_name;
$rss = get_category_feed_link($cat->cat_ID,'rss2');
$atom = get_category_feed_link($cat->cat_ID,'atom');
$link =get_category_link($cat->cat_ID);

// Show the output
$output = "Subscribe to <a href=".$link.">".$name."</a> posts: <a href=".$rss.">RSS</a> or <a href=".$atom.">Atom</a>";
echo $output;

Advertisements

0 Responses to “Snippet: Subscribe to category’s RSS feed”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: