Drupal Theming RSS Feed Views
Posted on: Friday, June 5th 2009 by Justin Tsang

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

Comments

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

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

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?

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

}

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.

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

I tried your code but it creates broken thumbnails. When I look at the broken image address it shows that the complete filepath is not being properly generated: http://www.mysite.com/files/imagecache/user_image_default/

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.

Great THX!

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.