get_the_post_thumbnail_url()
get_the_post_thumbnail_url( int|WP_Post $post = null, string|array $size = ‘post-thumbnail’ )
返回文章缩略图URL。
Return the post thumbnail URL.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$post | (int | WP_Post) | 可选 | Post ID或WP_Post对象。默认值为全局$post。 |
$size | (string | array) | 可选 | 用于检索高度和宽度维度的源或平面数组的注册图像大小。 |
返回(Return)
(string|false)发布缩略图URL,如果没有可用的URL,则为false。
源码(Source)
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.4.0 | wp-includes/post-thumbnail-template.php:213 | 1 function | 2 |
笔记(Notes)
不要忽略第一个参数。
否决了@thelilmercoder发布的示例,因为它不适合使用此函数。
值得注意的是,如果你上传一个较小的图像(比如说600像素宽)并用它来获取一个特定的较大图像(比如说,1920像素宽的封面),它将返回原始图像,而不是返回false。
get_the_post_thumbnail_url() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_the_post_thumbnail_url/