0

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?

2 Answers 2

1

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.

1
  • 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
    Commented Oct 8, 2011 at 15:31
0

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" />';
1
  • 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
    Commented Oct 8, 2011 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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