人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

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



●質問者: gonee
●カテゴリ:ウェブ制作
○ 状態 :キャンセル
└ 回答数 : 0/0件

回答がありません
関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ