Customize RSS Feeds generated by Views2 in Drupal 6

| | 1 min read

The Views module in Drupal provides a Feed display that will allow for site owners to publish the content on their sites as RSS feeds. However, unlike a page or block display, the feed display does not allow for addition of custom tags inside the feed using the Views administration UI. There is however a way to add custom tags, attributes and values into the generated feed using hook_nodeapi.

Hook_nodeapi supports an 'rss item' operation which gets called whenever an item is inserted into the feed during the generation of a feed. The corresponding nodeapi call can be used by modules to insert custom tags to the feed.

For example, by inserting the following 'rss item' case to the nodeapi hook in a module

    case 'rss item':
      $custom_tags = some_function_call();
      $rss_items = array();
      $rss_items[] = array(
        'key' => 'key_name',
        'attributes' => array(
          'attribute1_name' => $attribute1_value,
          'attribute2_name' => $attribute2_value,
        ),
        'value' => $key_value,
      ); 
    return $rss_items;

you will be able to insert a tag

<key_name attribute1_name="attribute1_value" attribute2_name="attribute2_value">key_value</key_name>

For the 'rss item' nodeapi hook the function should return an array of items that are to be inserted corresponding to each node in the feed. Each item in the array should be an array of one key, zero or more attributes and optionally a value.

For more complex capabilities you will have to use the Feeds module instead of the default core feed functionality.