記事の一枚目の画像をリサイズしてアイキャッチに リサイズされません
-
よろしくお願いいたします。
WordPress 4.2.2を使っています。
記事の一枚目の画像をリサイズしてアイキャッチにしたいのですが、
下記記述でリサイズされません。
不備な点がわかられる方、ご教授よろしくお願いいたします。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”;
}else{
//サイズをリサイズ
$final_image = image_resize($first_img, 320, 320, true,”,”,100);
//サーバー内のパスなので、ファイル名だけ取得
$final_image = ‘/’.basename($final_image);
}
return $first_img;
}表示場所に
<img src=”<?php echo catch_that_image() ?>” />
4件の返信を表示中 - 1 - 4件目 (全4件中)
4件の返信を表示中 - 1 - 4件目 (全4件中)
- トピック「記事の一枚目の画像をリサイズしてアイキャッチに リサイズされません」には新たに返信することはできません。