Feeding the masses using Wordpress
When I decided to segregate the (sporadic but more substantial) main posts from the frequently updated shorts on If..Else, I'd neglected to pay adequate attention to the feeds.
Whilst you could choose to subscribe only to the shorts via the category feed, there was no opportunity to receive only the main articles in your feed reader. The main feed was an intermingled mess of both the shorts and the regular entries, which dampened the effectiveness of the arrangement.
If you take a look at the subscription page now, you'll see that things are altogether more useful. The seperate feeds should make things more manageable for subscribers.
Seperating the feeds
Out of the box, WP supports category feeds. Accessing these 'inclusive category' feeds is fairly straightforward; just append /feed/ to the end of the category page. However, what it doesn't offer is an 'exclusive category' feed , that is a feed that syndicates all posts except those from a particular category (in my case, excluding posts from the shorts category).
However, implementing an exclusive category feed is fairly simple. To exclude a category, what you'll need to do is open up your root index.php and add the line $cat=-n (where n is the category id). Make sure that you're editing the file in your blog root and not your theme's index.php and that you add it before the import of wp-blog-header.php i.e. http://example.com/index.php and not http://example.com/wp-content/themes/your-theme/index.php
What you should have is something like this:
<?php...$cat=-13;require('./wp-blog-header.php');...?>
Whilst this works, you'll find that in it's present state, it's not quite ideal. We'll need to do a little more work before this is usable.
Mixing the feeds
The problem with the above technique are that:
a) the entries for this category will be excluded from the main blog loop (which may or may not be what you want)
b) you may still want to offer a full feed with all the works intermingled together.
One way in which you can do that is by passing a parameter to specify the type of feed required. We can then handle that as is appropriate.
Firstly, what we'll need to do is try to work out if the user is requesting a feed instead of a page. In Wordpress, all the work goes through the index.php file in your blog root. When a feed is requested, a parameter called feed is passed as part of the URI.
After we verify that it is a feed being requested, we can then check what type of feed is being requested. In my case, I'll be offering main, shorts and a full feed. Turning this into code gives us the following
<?phpdefine('WP_USE_THEMES', true);if(isset($_GET['feed'])) {if(isset($_GET['type_of_feed'])) {if ($_GET['type_of_feed']=='main'){$cat=-13;} else if ($_GET['type_of_feed']=='shorts'){$cat=13;} else if ($_GET['type_of_feed']=='full'){choose to do nothing}}}require('.wp-blog-header.php');?>
Icing the feeds
Now we don't want to link to the feeds with unfriendly query strings. What we should be doing is making non crufty URI's for the feed. That means it's mod rewrite time.
I've decided on the following format:
| All posts | http://ifelse.co.uk/feed/ |
|---|---|
| Main entries only | http://ifelse.co.uk/feed/main/ |
| Just the shorts | http://ifelse.co.uk/feed/shorts/ |
Now to do this, you'll need to open up your .htaccess file and add the following (ideally above the line '# BEGIN WordPress').
RewriteEngine OnRewriteCond %{HTTP_HOST} !^ifelse.co.uk [NC]RewriteRule ^(.*)$ http://ifelse.co.uk%{REQUEST_URI} [R=301,L]RewriteRule ^(feed)/main/?$ /index.php?&feed=rss2&type_of_feed=main [QSA,L]RewriteRule ^(feed)/shorts/?$ /index.php?&feed=rss2&type_of_feed=shorts [QSA,L]RewriteRule ^(feed)/full/?$ /index.php?&feed=rss2&type_of_feed=full [QSA,L]
Presenting the feeds
Finally, I've decided to not link to the feeds directly. Instead, I've given them their very own page. The reason for doing so are two fold.
Firstly, not everyone knows what a RSS feed is. I've borrowed some of the ideas from D Keith Robinson's page on the matter to give a short blurb on what it does and how you can use them.
Secondly, by grouping them up in a single page, I can provide a bit more information on the different feeds.
Finally, the feeds are still linked in the page header. This means that it's still discoverable by feed readers and browsers.
Tasting the feeds
Finally, I've got a question/favour to ask of you guys. I gather that a few of you are subscribed to the feeds. Unfortunately, whilst I can measure the popularity of web visitors, I don't have any way of measuring how many people or how popular the feeds are.
So my questions are:
- Which of the offered feeds are you currently subscribed to?
- Do you prefer segregated feeds?
- Which type of entries do you prefer/read? The shorts or the mains? (Don't worry, i don't mind:-))
- What feed readers do you use?
If you don't want to comment, feel free to drop me an email.
Also, any other thoughts/suggestions on the matter?
Feed the discussion