Issue with wordpress thumnails – same thumnail displayed everywhere

I’m guessing the problem is this: $recent_posts[0][‘ID’]; and I don’t see $recent_posts being defined in your code, so what exactly is that $recent_posts and where/how did you define it?: $image = wp_get_attachment_image_src( get_post_thumbnail_id($recent_posts[0][‘ID’]), ‘full’ ); And you’re inside The Loop, so you could just call get_post_thumbnail_id() without having to specify the post ID — or … Read more

Add a default style if no Featured image is selected

You can test if the $thumb has any contents and then apply a class to the featured image block that you can use to hide the container. <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’ ); ?> <div id=”post” class=”featured-image <?php echo empty($thumb) ? ‘no-featured-image-class’ : ”; ?>” style=”background-image: url(‘<?php echo $thumb[‘0′]; ?>’)”>

How to automatically add first image of post as thumbnail?

Please try the code given below: function auto_featured_image() { global $post; if (!has_post_thumbnail($post->ID)) { $attached_image = get_children( “post_parent=$post->ID&amp;post_type=attachment&amp;post_mime_type=image&amp;numberposts=1” ); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail($post->ID, $attachment_id); } } } } // Use it temporary to generate all featured images add_action(‘the_post’, ‘auto_featured_image’); // Used for new posts add_action(‘save_post’, ‘auto_featured_image’); add_action(‘draft_to_publish’, ‘auto_featured_image’); … Read more