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); のサイズの画像を表示させるにはどうしたらいいでしょうか?