Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to add thumbnails to blog post listings independent of images in a blog post -- e.g. if there is no image in the blog post, can I add a thumbnail image?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Is it possible to add thumbnails to blog post listings independent of images in a blog post

set the 'featured image' when writing/editing your post; and use the_post_thumbnail() within the loop, in the template.

e.g. if there is no image in the blog post, can I add a thumbnail image?

dependent on a post image, you can check (in your template, in the loop) if the post contains an image, and then output the post thumbnail, for instance with:

if( !strpos(' '.$post->post_content, '<img ') ) the_post_thumbnail();

details depend on your design.

share|improve this answer
    
Thanks. I added images to the posts and I clicked 'Use as featured image' But I didn't click 'Insert into Post' It looks like it's doing the trick. I'm not sure if that's exactly what you mentioned here, but it sounds like it's along the right lines. –  Richard Oct 8 '11 at 15:31

You can use the has_post_thumbnail() conditional tag to check if the post has a thumbnail, if thumbnail was found, display it by calling the the_post_thumbnail() template tag. If there's no thumbnail found, display custom image.

Example:

if( has_post_thumbnail() )
    the_post_thumbnail();
else 
    echo '<img src="' . get_bloginfo( "template_url" ) . '/images/no-thumbnail.png" />';
share|improve this answer
    
I don't have much background knowledge on this: Where do I upload the thumbnail to? And do I add that code into the CSS? Is there a particular place in the CSS where I should add the code? Also, I have a style.css in a folder called 'wordfruit' and another style.css in a folder called 'twentyeleven' -- I think 'twentyeleven' stops hiccups with upgrades of wordpress, or something like that -- which style.css do I add the code to? This is to resolve the situation at wordpress.stackexchange.com/questions/30540/… –  Richard Oct 8 '11 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.