当我尝试get_the_post_thumbnail_url()在Wordpress中使用时,我有一种奇怪的情况.
更确切地说,我有这个变量:
$postImage = get_the_post_thumbnail_url('article-thumbnail-image');
Run Code Online (Sandbox Code Playgroud)
它返回一个空值.如果我使用:
$postImage = get_the_post_thumbnail_url();
Run Code Online (Sandbox Code Playgroud)
返回的值是正确的,但它具有不同的图像大小(150x150).现在奇怪的部分是我使用:
the_post_thumbnail_url('article-thumbnail-image');
Run Code Online (Sandbox Code Playgroud)
它显示正确的值,因为此图像大小已注册functions.php但我需要使用GET功能.
难道我做错了什么?
get_the_post_thumbnail_url()中有两个参数.您需要为第一个参数使用null或post_id/post,并且大小将是第二个参数. https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
| 归档时间: |
|
| 查看次数: |
8748 次 |
| 最近记录: |