is there any way to show an image for RSS feess in my wordpress page... it os because currently defaul wordpress RSS feeds will only show a text of other feeds from other site..how can i make my site show a thumb image of rss feeds of th other sites..below are example of the rss feeds on my site. plizzz help me.i really needs a help from all of u guys....
A:
Yes, you can "hook" into the RSS feed and call 1 attachment (thumbmail)
Add this line to your functions.php file...
This example will add 3 thumbs, but simply change the "numberposts" to your desired amount...
/* Adding 3 thumbs to the top of the post on RSS */
function rss_custom_format($content) {
//prob uneccessary but checking that it is in fact a feed
if(is_feed()){
global $post;
if(!$post->ID){return;}
$args = array(
'post_type' => 'attachment',
'numberposts' => 3,
'orderby' => 'menu_order ID',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'order' => 'ASC'
);
$attachments = get_posts($args);
if($attachments){
$thumb = '';
foreach($attachments as $attachment){
$thumb .= wp_get_attachment_link($attachment->ID,'thumbnail','true').' ';
}
}
}
$thumb .= '<div style="clear:both; width:100%;"></div>';
$content = preg_replace('`\[[^\]]*\]`','',$content);
$more = '<a href="'.get_permalink($post->ID).'">Read More ...</a>';
return $thumb.$content.$more;
}
add_filter('the_content_rss','rss_custom_format');
add_filter('the_excerpt_rss','rss_custom_format');
awats
2010-10-18 03:19:41
Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\xampp\blog\wp-content\themes\structure\functions.php on line 83 --> this is error happen when i put in on my theme functions.php
Beginner Pogrammer
2010-10-18 03:58:23
That usually means you're missing a closing ';' or a '}' somewhere in your code. Add one more '}' to the very end.
awats
2010-10-18 04:01:34
already put it and the same problem happen
Beginner Pogrammer
2010-10-18 04:05:18
can you paste in line 83? That's the most likey the culprit. I have used this code on several sites so I know it's good. I think you need one last '}'
awats
2010-10-18 04:07:40
/* Adding 3 thumbs to the top of the post on RSS */function rss_custom_format($content) {//prob uneccessary but checking that it is in fact a feedif(is_feed()){global $post;if(!$post->ID){return;}$args = array('post_type' => 'attachment','numberposts' => 3,'orderby' => 'menu_order ID','post_parent' => $post->ID,'post_mime_type' => 'image','order' => 'ASC');$attachments = get_posts($args);if($attachments){$thumb = '';foreach($attachments as $attachment){$thumb .= wp_get_attachment_link($attachment->ID,'thumbnail','true').' ';}?>
Beginner Pogrammer
2010-10-18 04:12:09
Apologies! The code I pasted in was cut off. I have updated the code. Looks like a quite a few important bits were cut off.
awats
2010-10-18 04:13:59
It still has a problem..it does't show anything
Beginner Pogrammer
2010-10-18 04:20:01
Try adding an arbitrary string to the feed url, you may be viewing the cached version. Example yoursite.com/feed?randomtext Also, I pasted the code I use in "code" format that I use, which additionally filters out the [...] and adds in a "read more..." in it's place.
awats
2010-10-18 04:25:50