- Subscribe and get the new articles every now and then directly in your reader — I recommend using Google Reader
Make separate RSS feeds for each category in ExpressionEngine
Read comments ‣ (4)
written by Marek Foss

It’s time to talk about ExpressionEngine (EE) for a change. If any of you can speak Polish, I recommend subscribing to EExpression.pl, a nice new site that talks about EE in my native language. Now, to the subject — let’s assume for a moment that you use the EE feed templates. If you are running a daily news site, there’s probably loads of different categories you are broadcasting. It would be nice if your readers could subscribe just to the topic they are interested in (on CNN you can), but without the need for you to create tons of separate feed templates. See how EE can do this task for you.
Here is the idea — the URL of the feed will contain the name and id of the category it represents. Depending on your hierarchy, it will be two particular segments of the URL. For example, my main template group is named blog, and my feed template is named rss. Therefore, my main feed link is:
f055.net/blog/rss/
f055.net/{segment_1}/{segment_2}/
You can see the two segment variables, accordingly. First segment holds the string blog, while next contains rss. There are 9 segment variables. But we won’t need that many here. Our categorized feed link will look like this:
f055.net/blog/rss/News/1
f055.net/{segment_1}/{segment_2}/{segment_3}/{segment_4}/
Obviously, News is the category name, and 1 is the category id. And segments 3 and 4 hold these values, respectively.
Since we know all this, time to start modifying the feed template. Locate your weblog entries tag, it should look similar to the one below, and add the category parameter like this:
{exp:weblog:entries weblog="{master_weblog_name}" category="{segment_4}" rdf="off" dynamic_start="on" disable="member_data|trackbacks"}
Segment 4 represents the category id. Luckily, if it’s empty, all the categories are being displayed, so this will work for the main feed as well. But the feed title won’t. The best option is to make an if statement. Your regular feed title would be similar to this:
<title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
But it’s better to distinguish your category feeds with a clear indication of what they are about, just like that:
{if segment_3 != ""}
<title>{exp:xml_encode}{segment_3} - {weblog_name}{/exp:xml_encode}</title>
{if:else}
<title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
{/if}
Here, we change the title whenever the 3rd segment, the category name, is not emtpy. Now we are done with the feed template, but how are we going to pair up the category names and ids? Not by hand. Let’s leave it to EE Categories tag. In the HTML header, type the following code:
{exp:weblog:categories weblog="{my_weblog}" style="linear"}
<link rel="alternate" type="application/rss+xml" title="RSS - {category_name}" href="http://f055.net/blog/rss/{category_name}/{category_id}" />
{/exp:weblog:categories}
Assuming you have your weblog name in the {my_weblog} variable, this code will automatically embed links to all your categorized feeds, and give it nice names. Be sure to also include in the header a link to the main feed with all categories. So, once the user click on the RSS icon in the browser’s URL bar, there will be a nice list of all feeds, with category names.

My blog doesn’t use separate feeds, because I prefer FeedBurner over the native EE syndication. But I can’t say it’s not tempting to actually move to EE fully and have nice, categorized feeds. It looks professional, and gives the users more flexibility in reading the articles. I have to seriously think about it. And what would you prefer? Let me know in the comments! In the mean time, be sure to subscribe to my feed.
Title image by AleksRoks.
Comments
Nice article. Not sure what I would prefer. I’m just happy if I get RSS to work in EE.
Pretty useful. Always nice to find something on EE, info is sometime scarce.
Thanks for this article. I was looking to do just this exact same thing. I’m also considering feedburner. I guess I’ll have to make mind mind up.
Thanks again.


