- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/has post thumbnail
提供: WordPress Codex 日本語版
< 関数リファレンス
2010年3月3日 (水) 21:03時点におけるBono (トーク | 投稿記録)による版 (en:Template Tags/has_post_thumbnail 18:08, 4 February 2010 Kyuumeitai 版を翻訳用にコピー)
Description
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.
Usage
%%% <?php has_post_thumbnail( $post_id ); ?> %%%
Parameters
- $post_id
- (int) (Optional) Post ID.
- 初期値: 'ID', the post ID.
Examples
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" />'; } ?>
Change Log
Since: 2.9.0
Source File
has_post_thumbnail() is located in wp-includes/post-thumbnail-template.php
.
最新英語版: WordPress Codex » Template Tags/has_post_thumbnail (最新版との差分)
Related
投稿サムネイル: has_post_thumbnail, the_post_thumbnail, get_post_thumbnail_id, get_the_post_thumbnail, add_image_size(), set_post_thumbnail_size()
関数リファレンス、テンプレートタグ目次もご覧ください。