wordpress: use post-thumbnail if set?
hey guys, i hope there are a few wordpress experts out t开发者_开发百科here that can help me with ths. i'm using:
the_post_thumbnail('medium');
to view a post-thumbnail that can be set for every post in the backend.
however, if there is no postthumbnail set i want to print out a different image. any idea how i can check the function to find out if a post-thumbnail for a specific post is set?
thank you
<?php if( get_post_thumbnail_id() ):
the_post_thumbnail( 'medium' );
else: ?>
<img src="some_other_image.png" alt="" />
<?php endif; ?>
The above code will work fine, Though i think the write way would to show your post would be like this:
// Wrap it
if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) {
the_post_thumbnail( 'medium' );
} else {
// If there is no thumb, show a default one.
echo '<img src="'.get_bloginfo("template_url").'/images/default-post-thumbnail.gif" alt="" />';
}
Not much difference, just the wrapper.
Source: How to use Post Thumbnails Feature in Wordpress!
精彩评论