I'm trying to get the post thumbnail in the sidebar which is in essence outside the loop.
For some reason it seems impossible!!!
I have tried all kinds of ways.
Here is the wirking code: (I have edited the code now that I found it)
global $wp_query; $post_id = $wp_query->post->ID; if (has_post_thumbnail( $post_id ) ): $image_id = get_post_thumbnail_id($post_id); $imazz = wp_get_attachment_image_src($image_id,'medium',true); $image_url = $imazz; $image_url = '<img src="'.$image_url.'" alt="'.the_title().'" />'; else : php $image_url = '<img src="'.get_template_directory_uri().'/images/logo-pic-inv.jpg" width="500" height="333" alt="'.__("Δημοσιεύσεις","44db").'" />'; endif;
I have also tried using the following code:
get_the_post_thumbnail($post->ID); // using the post id
get_the_post_thumbnail($post_id); // using the fetched post id
any help would be very much appreciated. Thanks