In a multisite installation, I have a loop set up on my main blog that displays all posts from sub blogs, along with a thumbnail image. The image is important and without one will break the grid.

Is there a way to reject posts that do not have a featured image?



Try to use the has_post_thumbnail function. From the codex:

//This must be in one loop

if(has_post_thumbnail()) {
} else {
    echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
  • Thanks, that's a nice solution: using a default image if one isn't supplied by the user. Would it be terrible difficult to set up some conditional statements to use a different image based on post format? – jw60660 Sep 27 '11 at 9:23
  • No, see codex.wordpress.org/Post_Formats, you may do a switch / if block using has_post_format('your_format_of_choiche'). Note that you need Wordpress > 3.1 to do that! – keatch Sep 27 '11 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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