Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you modify the fields output in Drupal's RSS Feeds

Tags:

rss

views

drupal

Trying to modify the RSS feeds created by Views module in Drupal.

Since there are no 'theme_' hooks for the RSS feeds (rightfully as XML is theme-less), I need an alternate way to modify the fields that are output into the RSS, preferably using template.php if possible.

http://api.drupal.org/api/function/format_rss_item/6 looks promising as that is where each row is created, but it doesn't

node_feed() is what collects the nodes, creates the additional fields, and then calls format_rss_item().

Specifically, we need to remove the dc:creator element from the $extra array created in node_feed()

like image 657
Montana Harkin Avatar asked Jan 05 '10 15:01

Montana Harkin


People also ask

What is RSS feed in Drupal 9?

RSS stands for Really Simple Syndication – a web feed format for publishing frequent updates of site content such as news, blog posts, etc. Publishers benefit from RSS feeds because this lets them syndicate their site content automatically.

How do I display an RSS feed?

Right click an empty space on the website you'd like an RSS feed for, then click View Page Source (the exact wording may vary depending on your browser). If searching for rss doesn't work, try atom instead. Look for an RSS URL, as you can see above, then copy it into your feed reader.


2 Answers

If you go into a specific content type, you can set the RSS display fields as per this post:

http://redfinsolutions.com/redfin-blog/show-hide-fields-views-generated-drupal-rss-feed

like image 96
Cameron Avatar answered Oct 06 '22 18:10

Cameron


I am adding another answer, as I have recently had to do this and managed to do it without modifying data in the theme layer.

You can add a preprocess function to your view. It is a bit of work though.

There are some guidelines here, but they are a bit confusing. Here is my summary of how to do this.

First make sure your modules weight is > views

Secondly copy the template you would like to add a preprocessor to to your modules directory. Rename it to be something in the list of templates in theming information.

Then edit hook theme like this (but change to use the existing view that you need to override.

function mymodule_theme($existing, $type, $theme, $path) {
  // Copy the exsisting views theme from the existing array.
  $override = $existing['views_view_row_rss'];
  // Add my preprocessor to the list of preprocess functions
  $override['preprocess functions'][] = 'mymodule_myfunction';
  // Point to a template so that this view will be used.
  $override['template'] = 'my_more_specific_template_name';
  $override['path'] = drupal_get_path('module', 'path');
  unset($override['file']);
  // Return your theme handler.
  return array('my_more_specific_template_name' => $override);
}

You should then be able to write your preprocess code in the function mymodule_myfunction.

like image 33
Jeremy French Avatar answered Oct 06 '22 18:10

Jeremy French