tags:

views:

41

answers:

1

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

alt text

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
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
That usually means you're missing a closing ';' or a '}' somewhere in your code. Add one more '}' to the very end.
awats
already put it and the same problem happen
Beginner Pogrammer
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
/* 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
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
It still has a problem..it does't show anything
Beginner Pogrammer
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