Tech Blog :: Theming RSS items in Drupal 6


May 7 '10 11:57pm
Tags

Theming RSS items in Drupal 6

This evening I was trying to make a custom RSS feed using Views, that would replace the node body (in <description>) with a CCK field. For other types of output, this involves making a preprocessor for the Views row, or using hook_nodeapi to modify the node content, but RSS feeds don't seem to allow any of that flexibility.
Hook_nodeapi has an 'rss item' op, but I could only get it to add elements, not replace existing ones. The 'alter' op was triggered, but changes I made to the content with it didn't follow through. The only one that seemed to work was 'view', which is klugy, and incomplete, because fields added through CCK's display/rss settings are put on afterward.
Anyway, this is the best I could figure out -- if anyone knows a better way, I'd love to hear it.

function HOOK_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  // replace the <description> on feed/special-feed with field_blurb
  if (arg(0)==='feed' && arg(1)==='special-feed' && $op === 'view') {
    if (isset($node->field_blurb) && !empty($node->field_blurb[0]['safe'])) {
      $node->content['body']['#value'] = $node->field_blurb[0]['safe'];
    }
    else {  // empty otherwise
      $node->content['body']['#value'] = '';
    }
  }

You could try http://drupal.org/project/views_rss module. It allows you to choose Fields display style instead Node imposed for feeds. So you can pick any field manually and do all stuff with it. Plus, it respects the Rss 2.0 and even allows GeoRSS.

Check out Display Suite and related modules, that might let you do what you want in a very neat way, plus it supports Features.

Why wouldn't you just use something like feeds - http://drupal.org/project/feeds or a competing module to import RSS as nodes? If I need anything more than real basic that's what I use

Thanks for the comments! I ended up using Views RSS. I needs at least Views 2.9, though (I was running 2.8), because prior to that there is no "Node: Path" field which would go into the <link> field.
Feeds is fine on the receiving side - although the mapper doesn't allow custom/CCK mappings (without coding it I guess), so there's still really no way to sync complex node structures between 2 sites with RSS.
This is now live, powering the "Latest News" block on NewLeafDigital.com. It took much longer than it should have to get it all working, though.

Post new comment

Don't bother putting in spam links. They'll be set to rel=nofollow and will be removed and reported as spam shortly after submitting.

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Are you human?