Drupal Theming RSS Feed Views

Fri, Jun 5, 2009 by Justin

A lot of RSS feeds are very plain and boring, which sometimes results to unsubscriptions or plain out ignoring your feed. Web designers should spend some time to make these more readable and more useful to bring in more traffic.

A few reasons why we should include images in RSS feeds is that it draws in users and also gives a visual representation of content. Think of it as a blog landing page. Another reason is that a few sites use aggregators that pull your RSS feeds so that will lead to more traffic.

I had this problem for the longest time of theming and adding images to a RSS feed View. I always got the default feed of just the title and some teaser text. It was too plain, no dates, and no images even when I added fields to the view. Googling for sample code and solutions was not much of any help, so here my purposed solution for all you readers!

1. Install Modules
Modules you need:
Views: http://drupal.org/project/views
Contemplate: http://drupal.org/project/contemplate
Imagecache: http://drupal.org/project/imagecache


2. Create your RSS Feed view
Your content type should have an image field that you will use to be displayed in your RSS feed.


3. Create your imagecache preset for your RSS feed.
Don't make it too large as many feed readers are small.


4. Configure contemplate template settings
Navigate to Content management > Content templates or /admin/content/templates


5. Open Content Templates
For the content types that you want to theme click on edit template.

Edit Templates


6. Edit Template
Open the RSS fieldset
Check box "Affect RSS output"
Theme your node output for your RSS feed. Under RSS Variables you can see all the variables you have access to and here is where you would include the imagecache theming.

Edit RSS Output


7. Final Touches
Now any time the node type is used in a RSS feed it will be themed. You can even write a switch statement or if statement if you need to theme it differently on different RSS feeds using arg[0] too.


Final result examples could look like:

TechCrunch
TechCrunch


ReadWriteWeb
Read Write Web

Zedd posted on July 16, 2010 10:47 pm

I don´t think men are going to read your rss because it has so much nice images also this is not gonna make your text more intresting.
Who cares for some standrised images like...

Don´t get me wrong images are a great contributing to the text, when done right, butt less is more and whit this standard templates I am almost sure that it is better to forget.

Jorgen Sundberg posted on May 24, 2010 10:54 am

I am really struggling with this, why on earth don't images simply convert to the RSS feed in Drupal...?!

efendi posted on February 15, 2010 4:04 pm

can someone explain me, how to create a view who shows a rss for every single node? i'm trying but it's realy diffucult for me. thanks.

admin posted on August 4, 2009 11:52 pm

Lets say you have 2 rss views, one for your blog and one for your overall website and lets say your blog rss feed you want to display everything and the overall website rss just a teaser.

You could theme your RSS feed differently by an if statement using the feeds URL. Something like

if(arg(0) == 'rss_blog.xml') {

// THEME THIS WAY FOR YOUR BLOG ...

} else {

// THEME THIS WAY FOR OTHER FEEDS

}

Anonymous posted on August 1, 2009 4:56 am

This is excellent! Can you post a little more about how to use "if statement if you need to theme it differently on different RSS feeds using arg[0]". What would the if statement say?

admin posted on June 8, 2009 11:32 pm

There should be a way to do it with node.tpl.php but I would suggest not to "hard-code" it, due to changes to the content type or your rss feed in general.

-justin

Drupal Theme Garden posted on June 8, 2009 9:21 am

Thanks for this article.
Is it possible to have the same result, but with "hard-coded" code in tpl file in your theme?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h2>
  • Lines and paragraphs break automatically.

More information about formatting options