サムネイル画像を取得する関数 wordpress

楽にサムネイル画像をアーカイブページに出すことができます!
素敵~~!メモです。
今日は妹ちゃんの誕生日です。オメデトゥー。

まずはfunctions.phpに下記を追加。
[php]
/*
* $type=’thumbnail’|’medium’|’large’|’full’;
* $num is the number of <a onclick="javascript:pageTracker._trackPageview(‘/outgoing/blog.knym.net/items/tag/image’);" href="http://blog.knym.net/items/tag/image">image</a> order.
*/
function the_image($type=’thumbnail’,$num=0){
global $post;
$post_ID = $post->ID;
$files = get_children("post_parent={$post_ID}&post_type=attachment&post_mime_type=image");
if (!empty($files)){
$keys = array_keys($files);
$img_num=$keys[$num];
echo wp_get_attachment_image($img_num,$type);
}
}
[/php]

archive.phpに
[php]
<?php the_image(); ?>
[/php]

サムネイルサイズの変更で反映してくれる。
プラグイン使うより簡単~~!
ありがとうございますー!

参考サイト:WordPressの投稿記事で使われているサムネイル画像などを取得する関数 the_image

%d人のブロガーが「いいね」をつけました。