投稿の画像を抽出するために、この関数をよく使用します。
function first_post_image($content) {
$first_img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
$first_img = $matches [1] [0];
return $first_img;
}
次に、次のコードで画像を表示します
<?php $postimage = first_post_image(get_the_content()); ?> // catch the image
<img src="<?php echo $postimage; ?>" /> //view the image
前回のテンプレート (wp) でこの関数を使用しようとしましたが、画像が表示されません。タグ img と src 属性が表示されますが、空です。
誰かが私を助けることができますか?ありがとう