has_post_thumbnail()通过ID判断文章是否有缩略图/特色图片

目录

描述

Returns a boolean if a post has a Featured Image (formerly known as Post Thumbnail) attached (true) or not (false).

Note: To enable featured images / post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.

has_post_thumbnail() 描述

用法

 <?php has_post_thumbnail$post_id ); ?> 

has_post_thumbnail() 用法

参数

$post_id

(integer) (可选) Post ID.

默认值: 'ID', the post ID.

has_post_thumbnail() 参数

示例

This example first checks if there is a Post Thumbnail (aka Featured Image) set for the current queried item. If there is a Post Thumbnail set, it returns the Post Thumbnail. If not, it echoes out a default image which should be located in the current theme's image folder (assuming the folder is in the theme's root directory).

You can use set_post_thumbnail_size() to set a default size for your thumbnail. Alternatively, you can add new image sizes to the defaults by use add_image_size().

has_post_thumbnail() 示例

源文件

has_post_thumbnail() 函数的代码位于 wp-includes/post-thumbnail-template.php.

has_post_thumbnail() 源文件

相关