functions.phpに以下を記述します。
/* アイキャッチ画像がなければ標準画像を取得する*/
function get_eyecatch_with_default()
{
if (has_post_thumbnail()) :
$id = get_post_thumbnail_id();
$img = wp_get_attachment_image_src($id,);
else :
$img = array(get_template_directory_uri() . '/img/post-bg.jpg');
endif;
return $img;
}
次にsingle.phpに以下を記述します。
?php $img = get_eyecatch_with_default(); ?>


コメント