Changing your RSS feed to include image node thumbnails

A site we worked on wanted to have the thumbnails for image nodes to be included in the RSS feed, so subcribers can get a preview of what the image is like before clicking.

So, using the 'rss item' $op to hook_nodeapi, we were able to do this in a relatively simple way, with no need to modify either Drupal's core nor the image module.

This article applies to Drupal 5.x, but may also be adapted to 4.7 and 6.x.

First, create a custom.info file under sites/all/modules or wherever you put your non-core modules.

Put the following in the file:

; $Id$
name = Custom
description = Customizations for this site 

Then, create a custom.module in the same directory, and put this in it.

<?php
function custom_nodeapi(&$node, $op, $teaser, $page) {
switch($op) {
case 'rss item':
$extra = NULL;
if ($node->type == 'image') {
// This is an image node, get the thumbnail
$extra = l(image_display($node, 'thumbnail'), 
"node/$node->nid", array(), NULL, NULL, FALSE, TRUE);
$node->teaser = $extra . $node->teaser;
$node->body .= $extra . $node->body;
return;
}
}
}

Visit Administer -> Build -> Modules and enable the custom module that you just created.

Now, RSS feeds will contain the image of the thumbnail.

Enjoy ...

Contents: 

Comments

Weird result

The feed now pulls an image from my site but it's my site logo/header image and not an image from the actual feed.

My Drupal install only accessible by direct linking so please add this to my url when you look.

unusualartists.com/lounge/aggregator/sources/1

Any ideas why this would happen?
Thanks
Jon

I'm desperate

I'm desperate. I want to make more websites/blogs in drupal and this damn rss problem hold me to promote my rss. Also my email subscriptions are influenced by this damn problem. Can you help ? Please.....

Trying to Do Something Similar...

... so far without much success, with the RSS items for nodes created by the FeedAPI module -- I want the RSS headline to link back to an item's original URL, not to the node that FeedAPI creates on my site.

I've posted a support request in the FeedAPI queue -- see
http://drupal.org/node/200434 -- but figured that whatever help I get there might be useful to those who find this post and are trying to tweak their RSS feeds in other ways.

body text repeated

This works for me except that, if there is any text in the body field, it is displayed twice in the feed item...both before and after the image. Any suggestions?

Making it work with 6.x

Hi there,
thanks so much for this fix. Since a previous commenter wanted to know how to make this work in 6.x:
in the .info add: core = 6.x
in the .module change $extra = l(image_display($node, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE);
to $extra = l(image_display($node, 'thumbnail'), "node/$node->nid", array('html' => TRUE));

thumbnail

My tryingto add a thumbnail to my feed has lead me here, this post looks promising but you dont instruct where in the .info file to add core = 6.x

Cannot make it worked

1.
Is it necessary to end php text with "?>" ?
I've tried both veriants and no success.

2.
My version looks:
INFO
; $Id$
name = Custom
description = Customizations for this site
core = 6.x

MODULE
<?php
function custom_nodeapi(&$node, $op, $teaser, $page) {
switch($op) {
case 'rss item':
$extra = NULL;
if ($node->type == 'image') {
// This is an image node, get the thumbnail
$extra = l(image_display($node, 'thumbnail'), "node/$node->nid", array('html' => TRUE));
$node->teaser = $extra . $node->teaser;
$node->body = $extra . $node->body;
return;
}
}
}
?>

After installation I uncheck and recheck the custom module in modules, then resync my feedburner feed. Then try in Safari feed-reader and Google Reader. See no images. The same in direct drupal feed-xml (http://domain/rss.xml).

Could you advise me where i am wrong?