プロフィール

とん吉
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
MENU
最近の記事
節分 (2/4)
静岡新聞 2013年2月12日 夕刊 (2/13)
息子が図書券で買った本 (9/10)
WP|カスタム投稿の用意 (9/4)
WordPress|記事内の一枚目の画像を取得する (8/28)
息子のため (7/26)
念願のベットが到着!! (7/20)
過去記事
最近のコメント
Roseanne Keys / Custom Fields Searchとカス・・・
Doreen Salo / Custom Fields Searchとカス・・・
Leigh Banuelos / WP|Contact form 7へタイト・・・
Josef Monahan / Custom Fields Searchとカス・・・
Lionel Fegan / WP|Contact form 7へタイト・・・
ブログ内検索
WordPress|記事内の一枚目の画像を取得する
2012年08月28日
1. function.phpに下記の記述を追加
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "画像がない場合に表示させる画像のURLを記述する";
}
return $first_img;
}
?>
2. 画像を追加した場所に下記を挿入する
<img src="<?php echo catch_that_image(); ?>" alt="" width="20" height="20" />
これでOK!!
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "画像がない場合に表示させる画像のURLを記述する";
}
return $first_img;
}
?>
2. 画像を追加した場所に下記を挿入する
<img src="<?php echo catch_that_image(); ?>" alt="" width="20" height="20" />
これでOK!!
Posted by とん吉 at 13:25│Comments(0)
│WordPress
アクセスカウンタ