WordPress as CMS – RSS Feeds for Sections!

By Sol in Lab

Actually, that was yesterday. After I got RSS feeds working again (again, a result of my custom rewrite rules), I set out to get feeds for sections working. Simply put, I wanted there to be a feed for every section (e.g. http://domain.com/section-name/feed) which displayed the latest items (articles, blog posts, etc.) in that section. As my implementation of sections doesn’t exactly jive with the way the feeds work in WordPress (more on this in a later post), I was sure getting this feature working was going to require some twisty code. I sat staring out the window for what seemed like an eternity (probably 10 minutes), working out all the possible solutions to this as I could imagine. For the most part, I was coming up blank. So, I decided it might be a good idea to first find out how WordPress creates its RSS feeds (did I forget to mention that I hadn’t actually done that yet?). I was relieved to find that RSS feed generation in WordPress is amazingly simple. You’ve got a template file for each feed type (RSS, RSS 2, Atom, etc.) in the root directory of the WordPress install. These template files are very similar to the template files in themes (they’ve even got their own template tags). From there, it was just a simple matter of having the template check if the requested page was for a section, fetching the items for that section, and inserting the data in the proper XML tags. After that, I added a custom rewrite rule (no conflicts this time, I swear) and I had working RSS feeds for sections, in about 5 minutes!

The only downer is that currently, WordPress keeps the RSS templates in the root directory. This of course means that themes cannot include templates for customizing the RSS feeds. It also unfortunately means that a plugin cannot directly generate the RSS feeds (you can only append data to certain sections of the RSS feeds using hooks), so providing an integrated drop-in CMS solution with working feeds for WordPress can’t be a 1-step process (it is now a 2-step process– bummer, I know). I have a few ideas that I need to explore, so there may still yet be hope.

Today, I am working on displaying items for all sub-sections in the parent section(s) as well. Previously, sections would only display items in that section, but not items belonging to the current section’s sub-sections. I found that somewhat limiting (as that would require users to navigate several levels down just to see if a sub-section had any new items), so I changed to display all items belonging to the current section and its sub-sections. I may provide an option to turn this functionality on/off later on (though at this point, I can’t see why turning it off would be desirable edit: I thought of at least a few situations where you would want to control this, so I’m adding the option).

Actually, I should have said I was working on it, because I just finished it.

Now: Lunch

Later: Filtering display of items to the selected section and category. I have a feeling this one will be interesting.