- サイトデザイン工事中です。ご意見をお寄せください。
- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
テンプレートタグ/has post thumbnail
提供:WordPress Codex 日本語版
< テンプレートタグ
タグ一覧: テンプレートタグ | インクルードタグ | 条件分岐タグ | その他の関数 | phpdoc
使い方: テンプレートタグ入門 | パラメータの渡し方 | 初心者の方へ | その他のテーマ関連資料
目次 |
説明
Returns a boolean if post has an image attached (true) or not (false).
Note: To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file.
使い方
<?php has_post_thumbnail( $post_id ); ?>
Parameters
- $post_id
- (整数) (任意) Post ID.
- 初期値: 'ID', the post ID.
用例
This script asks if there is, actually, a thumbnail in the post. If it's not, it will put a default image.
<?php
//This must be in one loop
if(has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
?>
変更履歴
- 2.9.0 : 新規テンプレートタグ
ソースファイル
has_post_thumbnail() is located in wp-includes/post-thumbnail-template.php.
最新英語版: WordPress Codex » Template Tags/has_post_thumbnail (最新版との差分)
関連
has_post_thumbnail, the_post_thumbnail, get_post_thumbnail_id, get_the_post_thumbnail