• サイトデザイン工事中です。ご意見をお寄せください
  • 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

テンプレートタグ/has post thumbnail

提供:WordPress Codex 日本語版
移動: 案内, 検索

情報募集中 このテンプレートタグの説明やコードの書き方、活用例参考になるページがあったら、他のWordPressユーザのためにどんどん書き込みましょう! 該当部分を編集するか、このページのノートまたはフォーラム等で教えてください。

目次

説明

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" />';
}
?>

変更履歴

ソースファイル

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

個人用ツール
名前空間
変種
操作
このサイトについて
特集
サーバ別情報
リファレンス
ドキュメント整備
ツールボックス
他の言語