WordPressの投稿記事内の一番最初の画像を独自画像サイズで表示する方法


functions.php 内で下記のように、画像サイズと、投稿記事内の一番最初の画像を取得するコードを書きました。
--------------------------------------------------
add_image_size('list',308,9999,FALSE);

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 = "/wp-content/themes/hogehoge/images/top/noimages.gif";
}
return $first_img;
}
--------------------------------------------------

front-page.php 内で下記のように書いています。
--------------------------------------------------
<?php if ( $first_image = catch_that_image() ) : ?>
  <div class="pic"><a href="<?php the_permalink() ?>""><img src="<?php echo do_shortcode( $first_image ); ?>" alt="<?php the_title(); ?>に関する画像" width="308" /></a></div>
<?php endif; ?>
--------------------------------------------------
上記の記述ですと、投稿内で表示しているサイズの画像が表示してしまいます。

add_image_size('list',308,9999,FALSE); のサイズの画像を表示させるにはどうしたらいいでしょうか?

回答の条件
  • 1人5回まで
  • 登録:
  • 終了:2014/07/31 11:15:03
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

回答0件)

回答はまだありません

コメントはまだありません

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません