Getting the post id for RSS thumbnail
-
Hey,
I am trying to get the posts id within the rss feed so i can display the posts thumbnail as i am using press75.com “Simple Post Thumbnails” plugin and how you would get the thumbnail normally from within a post would be like:
get_thumbnail($post->ID);
I have inserted the following code into my functions.php file to display an image within the rss:
function feedFilter($query) { if ($query->is_feed) { add_filter('the_content', 'feedContentFilter'); } return $query; } add_filter('pre_get_posts','feedFilter'); function feedContentFilter($content) { $thumbId = get_post_thumbnail_id(); if($thumbId) { $img = wp_get_attachment_image_src($thumbId); $image = '<img align="left" src="'. $img[0] .'" alt="" width="'. $img[1] .'" height="'. $img[2] .'" />'; echo $image; } return $content; }
This will place a thumbnail next to the text within the rss feed.
So to display my thumbnail from my currant plugin i would have to retrieve the posts id as this line of code does:
$img = wp_get_attachment_image_src($thumbId);
but i am using the custom plugin so i would need to use something like:
$img = get_thumbnail($post->ID);
the only thing is $post->ID wont work outside the loop so my question is does anyone know how i can achieve this type of operation outside the loop?
- The topic ‘Getting the post id for RSS thumbnail’ is closed to new replies.