bioneural.net site preferences

Accessibility

Toggle width/ text size:

style

Default/Alternate

Suits visual impairment, mobile devices

Styling

Change the theme:

layout

NB: may reduce functionality

Link behaviour

Links with an icon are off-site:

links

Right-click any link to optionally open in a new window or tab


Internet

Customizing feeds in WordPress 2.x

This is not as easy as it sounds, especially given that WordPress offers a variety of feed formats and the lead developer attests to its flexibility. After much frustration, a bit of help here and there, and a large dollop of trial-and-error, I finally figured out how to serve both a summary and a full-text feed, and to exclude a single category from one of them.

What did work is broke

Matt said:

...WordPress has the most comprehensive RSS support of any product I've seen: we produce a regular site feed, a site comments feed, a feed for every category, a comments feed for every post, a feed for every search, a feed for every month, and you can even combine and exclude categories to create a very customized category feed. All in 4+ flavors of RSS and Atom, with RSS 2.0 being the default.

Were to start? I started with this post, initially modifying my root index.php file as per the following (where category id=16 is the one I want to exclude from the "9rules" feed type):

<?php
define('WP_USE_THEMES', true);
    if(isset($_GET['feed'])) {
        if(isset($_GET['type_of_feed'])) {
        if ($_GET['type_of_feed']=='9rules'){
            $cat=-16;
        } else if ($_GET['type_of_feed']=='bookmarks'){
            $cat=16;
        } else if ($_GET['type_of_feed']=='full'){
            //do nothing
        }
    }
}
require('./wp-blog-header.php');
?>

The 9rules feed generated a WordPress database error; the other two feeds worked correctly! I then reverted to the original index.php file and tried Ben's suggestion (made in a comment on the above page) to use .htaccess. Whereas this worked (showing posts only in category 16):

# Test to show bookmarks only
RewriteBase /
RewriteRule ^9rules/feed/?$ /index.php?&feed=rss2&cat=16 [R,L]

This did not:

# Create a feed for 9rules.com excluding bookmarks
RewriteBase /
RewriteRule ^9rules/feed/?$ /index.php?&feed=rss2&cat=-16 [R,L]

So apparently you can't use cat=-(n) anymore; Ben subsequently confirmed that upgrading from WordPress 1.x to 2.x broke his rewrite rules. Bummer.

Another option, since I use the Sideblog plugin, would have been to exclude category 16 from the feed altogether (via Options > Sideblog). While effective, I felt this went against the whole idea of sharing bookmarks. Folk might be happy to subscribe to the main feed, but would likely neglect to take out out a second subscription to the asides/ bookmarks category—and so miss out of stuff I felt was especially noteworthy.

There's always another way. First, let's list some objectives.

Regular subscribers: objectives

These were my requirements for regular subscribers:

  • Offer an except-only feed with a "read more" link (IMHO this is the purpose of headline syndication; I prefer to decide whether to load a full page or not depending upon the quality of the excerpt. Have you tried viewing a full-text feed in a web aggregator or Safari? It can take an age to finish loading—not good!;
  • Include all posts, including an asides/ bookmarks category (called "QuickLinks" on my site);
  • Offer social bookmarking convenience;
  • Gather subscription statistics.

The feed URL will be http://www.bioneural.net/feed/

Content network: objectives

These were my requirements for syndicating original content to the 9rules.com network:

  • Offer a full-text feed as required by 9rules.com;
  • Dispense with the social bookmarking/ other feed customizations;
  • Include only original content, thus excluding posts in the asides/ bookmarks category;
  • Retain the ability to alter the feed characteristics (e.g. add or subtract categories, change feed format) without having to ask 9rules.com to alter the feed URL.

The feed URL will be http://www.bioneural.net/9rules/feed/

Regular subscribers: utilizing FeedBurner

I installed The FeedBurner Feed Replacement plugin. This plugin adds rewrite rules to your .htaccess file (more on this below) which, in a nutshell, allows you to redirect user agent requests for a standard feed to a FeedBurner account. For example, main all-inclusive main feed URL is http://www.bioneural.net/feed/, and this is set to redirect to http://feeds.feedburner.com/Bioneuralnet.

For reference, here is a snapshot of my FeedBurner feed in NetNewsWire, showing posts in all categories (category 16 posts are highlighted yellow):

Full-Feed

FeedBurner gives you the option to provide subscribers with a summary or excerpt only, set to a variable number of characters:

Feedburner-Summary

By activating this option (it is inactive by default) and making use of FeedFlare (an interactive item footer), you can enable subscribers to readily e-mail and bookmark (e.g. on del.icio.us, Digg) your content. More important, you make it accessible to those suffering lower bandwidth Internet connections or feed readers that choke when asked to display multiple full-text posts simultaneously. There are other advantages which may or may not concern you, such as directing readers to your full web page if you hope to generate income from advertising. Using this facility the post is striped of hyperlinks and of formatting (part of the reason it loads so rapidly):

Fb-Summary-Only

Content network: Rewriting 9rules in .htaccess

Before you can edit your .htaccess file you may need to unhide it. In Transmit, turn on "Show Invisible Files" from the View menu:

Transmit

Using a text editor (e.g. BBEdit) open the file and start editing after the FeedBurner re-direct rules. Here is a rewrite rule that does work, since we have avoided using cat=-(n). Instead, we are listing the category IDs of all the post categories that we do want to be included in the feed:

# Create a feed for 9rules.com
RewriteBase /
RewriteRule ^9rules/feed/?$ /index.php?&feed=rss2&cat=2,11,6,5,4,7,10,9,15,13,14,8,3 [R,L]

So the nice and semantic http://www.bioneural.net/9rules/feed/ will re-direct invisibly to the butt-ugly actual feed:

http://www.bioneural.net/index.php?&feed=rss2&cat=2,11,6,5,4,7,10,9,15,13,14,8,3

Back to NetNewsWire, and you'll now see (compare to above) that the (yellow) category 16 items are missing from the feed. There are still 10 items, but two of the posts have been replaced by older original content (highlighted green):

9Rules-Rewrite

When we click on a post title, instead of a brief unformatted text excerpt as above, you'll see that some basic structure, links, and images are preserved and included in the full post:

Formatted

Conclusion

We have achieved all of the above objectives, for both regular subscribers and for syndication to a content network.

6 responses to “Customizing feeds in WordPress 2.x”


  1. Comment 1 mark

    I am trying to figure out a way I can keep the summary option selected in wordpress under the syndication feeds but still keep an image to go with the summary. Can this be done?

  2. Comment 2 Bruce

    Hi Mark,

    First, just to clarify, you're not taking about the channel image ("feed logo") as per the RSS spec are you?

    What kind of image do you want to add? A static one? A dynamic one that reflects the post category, or an ad?

    As I understand it, when you choose Summary for syndication feeds in WordPress Admin (Options > Reading) you strip away all HTML tags—including those for embedded images.

    It seems that even a plugin like Better Feed, which lets you add custom elements, will only work if you enable full text feeds.

    If you used FeedBurner to summarise your full text feeds, you could use Photo Splicer to add an image from Flickr. You could set up an account specifically for this purpose, or selectively tag images in an existing account. Maybe you could even write a custom FeedFlare?!

    The only other option I can think of is to try manually hacking your "core" wp-rss2.php file. I had a quick go at this just now and couldn't get an image to display for summaries (but did insert a test image for full text feeds).

  3. Comment 3 Bruce

    Mark, an update!

    I managed to hack wp-rss2.php to show a static image together with summary syndication. Here is the hacked file so you can see exactly where to insert the edit (discovered by trial-and-error, and with assistance from the 9rules Clubhouse).

    If you want a dynamic image you could try inserting a PHP block in its place.

  4. Comment 4 Bruce

    ...or, if you have the Category Image plugin installed, replace the static URL in the hacked file with this:

    <?php c2c_the_category_image(); ?>

    ... and you'll get a category-specific image, for summary and/or full-text feeds.

  1. 1 Customizing feeds in WordPress 2.x | Open Switch
  2. 2 links for 2007-08-11 at pierson.homeip.net

Something to say?

Comments may be moderated (e.g. no commercial promotion), are subject to spam filtering, and should be relevant to this post—otherwise make contact.

Usable tags include <a href=""> <blockquote> <em>. Select any text and click to quote.