Codex tools: Log in
Languages: English • 日本語 • (Add your language)
Contents |
Returns a boolean if a post has a Post Thumbnail attached (true) or not (false).
Note: To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.
<?php has_post_thumbnail( $post_id ); ?>
This example checks if there is a Post Tumbnail attached to the post. If there is no Post Thumbnail attached, show a default image. (The default image has to be uploaded to a folder called "images" in the current theme's directory.)
<?php
//This must be in one loop
if(has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
?>
has_post_thumbnail() is located in wp-includes/post-thumbnail-template.php.
Post Thumbnails: has_post_thumbnail(), the_post_thumbnail(), get_post_thumbnail_id(), get_the_post_thumbnail(), add_image_size(), set_post_thumbnail_size()