Tech Blog :: rss


May 8 '10 12:57am
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'] = '';
    }
  }