投稿の添付画像の表示

エントリに添付画像がない場合は、falseを返すので、存在確認をした上で表示

$image01= get_post_meta($post->ID, 'image01', true);
$thumb= wp_get_attachment_image_src($image01, 'thumbnail');
if ( $thumb ) {
echo $thumb[0];
}

http://ja.forums.wordpress.org/topic/4784?replies=3(サムネールのURL取得)

$post_thumbnail_id= get_post_thumbnail_id( get_the_ID() );
$image= wp_get_attachment_image_src( $post_thumbnail_id, 'post-thumbnail' );
if ( $image ) {
 list($src, $width, $height)= $image;
 echo '<div style="background:url(' . esc_attr( $src ) . ')">';
} else {
 echo '<div style="background:url(no-post-thumbnail.png)">';
}

[emulsion_relate_posts]