How to display Post Thumbnails in WordPress feeds [CODE]

WordPress code | Rolands Umbrovskis | July 15, 2010 8:45 am 82 views | No Comments »

When year ago I was working on new functions for e-art.lv, I decide to use Post Thumbnails In WordPress Feeds. There were several reasons why we (e-art.lv) started to use that “feature“. We saw that some of RSS aggregators are usign these features from other RSS and Atom feeds.  We wanted them too… Here is my solution for post thumbnails in WordPress excerpt feeds.

post thumbnails in wordpress feeds. preview.

Code of Post Thumbnails In WordPress Feeds


// Post thumbnails in RSS from Simple Media Code http://blog.simplemediacode.com/?p=248 by http://Umbrovskis.com
function me3_rssthumbnails($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'medium', array('align' => 'left', 'alt' => $post->post_title)) . "\n" . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'me3_rssthumbnails');

Here comes code explanation:

we are taking existing content of RSS

me3_rssthumbnails($content)

we are taking uploaded image from post

has_post_thumbnail( $post->ID ))

Here we are taking medium size image from post, aligning it to left, and taking post title as descriptional text in alt attribute.

$post->ID, 'medium', array('align' => 'left', 'alt' => $post->post_title)

Download as WordPress plugin

More info about used WordPress functions

  • http://codex.wordpress.org/Function_Reference/has_post_thumbnail
  • http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
  • http://codex.wordpress.org/Function_Reference/add_filter

No Related Posts

 
 
draugiem.lv/say SekoMan.lv twitter Digg this! Add to del.icio.us! Stumble this! Add to Techorati! Share on Facebook! Seed Newsvine! Reddit! Add to Yahoo!

Rolands Umbrovskis

Web developer at "Simple Media Code" / Mediabox.lv

Follow Rolands Umbrovskis on Twitter or Facebook

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Note: This post is over a month old.

 



bt bt bt bt
plugin by DynamicWP
#