- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/has post thumbnail」の版間の差分
提供: WordPress Codex 日本語版
< 関数リファレンス
細 (整形・リンク調整、試験的にテーマテンプレートガイドを挿入、未翻訳) |
|
(相違点なし)
|
2014年4月21日 (月) 11:41時点における版
タグ一覧: テンプレートタグ | インクルードタグ | 条件分岐タグ | その他の関数 | Code Reference
使い方: テンプレートタグ入門 | パラメータの渡し方 | 初心者の方へ | その他のテーマ関連資料
説明
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, add_image_size(), set_post_thumbnail_size()
関数リファレンス、テンプレートタグ目次もご覧ください。