WordPress で記事に関連付けられたイメージのサムネイルを取得
.WordPress で記事に関連付けられたイメージのサムネイルを取得する方法をようやく発見。
参考にしたのは
[WP]Wordpress2.5~2.6 サムネイル画像を取得して表示
まんまそのまんまだけどこんな感じですね。
while (have_posts()){
$attachments = get_children(array('post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order'));
if ( is_array($attachments) ){
$first_attachment = array_shift($attachments);
$thumb = wp_get_attachment_thumb_url($first_attachment->ID);
}
}
あとはサムネイルのサイズを途中で変えた場合に、再生成を行う方法が知りたい・・・。
要調査だな。