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 ...

Comments

Wed, 2007/11/21 - 03:22

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

Tue, 2007/11/06 - 14:33

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.....

Wed, 2007/12/12 - 23:06

... 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.

Fri, 2008/04/11 - 13:19

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?

Tue, 2008/09/09 - 10:37

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));

Mon, 2010/10/18 - 14:35

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

Tue, 2008/12/16 - 11:42

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?

Pages

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting