# wp_get_attachment_thumb_urlを使う

- リンク: https://torounit.com/blog/wp_get_attachment_thumb_url%e3%82%92%e4%bd%bf%e3%81%86/
- 公開日: 2010-09-03T23:05:26+09:00
- 作成者: Toro\_Unit

wordpress3になってからアイキャッチ画像とかが設定できるようになったけれど、まだまだ
本文中の画像をサムネイル化して、表示するという需要もあるわけで。

そんなときに少し便利な関数wp_get_attachment_thumb_urlの実装例です。

[php]
 function get_thumb_url(){ $attachments = get_children(array(‘post_parent’
=> get_the_ID(), ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘orderby’
=> ‘date’)); if ( is_array($attachments) ){ $first_attachment = array_shift($attachments);
$thumb_url = wp_get_attachment_thumb_url($first_attachment->ID); return $thumb_url;}}[/
php] その記事の一番古い添付ファイルのサムネイル画像のURLを返します。たぶん。。。。

 wp_get_attachment_image_src()も似たような使い方ができますが、こちらはサイズをパラメーター
として渡さないとです。まぁこちらの方が便利な気がしますが・・・
