投稿のサムネイルが定義されておらず、投稿に複数の画像が含まれている場合と含まれていない場合があるため、次のように設定しました。
抜粋でタグをオフにし(抜粋でタグを有効にする抜粋プラグインがありました)、function.phpファイルに次を追加しました。
function catch_that_image() {
global $post, $posts;
$first_img = ''; ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
$post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
//Defines a default image
$first_img = "/images/default.jpg"; }
return $first_img;}
次に、投稿のタイトルと抜粋/コンテンツの間にあるメインのインデックステンプレートファイルに以下を追加しました。
<p><a href="<?php the_permalink() ?>" alt="<?php _e('Read full article', 'theme');?>" title="<?php _e('Read full article', 'theme');?>"><img src="<?php echo catch_that_image() ?>"></a></p>
ランダムノート:それは
スタイリングの理由で。
私を正しい方向に導いてくれてありがとう。