get_the_post_thumbnail

Sponsored Link

投稿またはページの編集画面内の設定したように投稿サムネイルを取得します。サムネイル画像は”attachment-thumbnail”クラスを与えられます。

Sponsored Link

Gets Post Thumbnail as set in post’s or page’s edit screen. Thumbnail images are given class “attachment-thumbnail”

get_the_post_thumbnailのテンプレートタグ使用方法

<?php echo get_the_post_thumbnail( $id, $size, $attr ); ?> 

get_the_post_thumbnailのパラメーター

id

(integer) (Required) 投稿IDです。

(integer) (Required) Post ID.

Default: None

size

(string) (Optional) 画像サイズ

(string) (Optional) Image size.

Default: ‘post-thumbnail’

attr

(string|array) (optional) クエリ文字列または属性の配列です。wp_get_attachment_imageを参照してください。

(string|array) (optional) Query string or array of attributes. See wp_get_attachment_image.

Default: None

$default_attr = array(
			'src'	=> $src,
			'class'	=> "attachment-$size",
			'alt'	=> trim(strip_tags( $attachment->post_excerpt )),
			'title'	=> trim(strip_tags( $attachment->post_title )),
		);

この記事は編集が必要とマークされています。編集することによってコデックスを助けることができます。

This article is marked as in need of editing. You can help Codex by editing it.

使用例

<?php $pages = get_pages(array('child_of' => 1)); ?> 
<ul>
   <?php foreach ($pages as $page): ?>
   <li>
   <?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
   <h1><?=$page->post_title?></h1>
   <?=$page->post_content?>
   </li>
   <?php endforeach; ?>
</ul>

その他のオプション

get_the_post_thumbnail($id);  // without parameter -> Thumbnail

get_the_post_thumbnail($id, 'thumbnail'); // Thumbnail
get_the_post_thumbnail($id, 'medium');// Medium resolution
get_the_post_thumbnail($id, 'large'); // Large resolution

get_the_post_thumbnail($id, array(100,100) ); // Other resolutions

注釈

投稿サムネイルを有効にするには、現在のテーマのfunctions.phpファイル内にadd_theme_support( ‘post-thumbnails’ );を含めなければなりません。

To enable post thumbnails, the current theme must include add_theme_support( ‘post-thumbnails’ ); in its functions.php file.

変更ログ

Since: 2.9.0

ソースファイル

get_the_post_thumbnail()は、下記内に位置しています。

get_the_post_thumbnail() is located in

  • wp-includes/post-thumbnail-template.php (the latest stable version)
  • wp-includes/post-thumbnail-template.php (the development version)

外部リソース

  • Everything you need to know about WordPress 2.9’s post image feature, by JustintAdlock.com
  • The Ultimative Guide For the_post_thumbnail In WordPress 2.9, by wpEngineer.com

関連テンプレートタグ

has_post_thumbnail, the_post_thumbnail, get_post_thumbnail_id, get_the_post_thumbnail

Sponsored Link