简体   繁体   English

如何使用get_post_meta在wordpress中获取缩略图

[英]How to use get_post_meta to get thumbnail in wordpress

I have a wordpress website and I am trying to get the thumbnail image (aka featured image) of a post. 我有一个wordpress网站,我正在尝试获取帖子的缩略图(又称特色图片)。 I can't use the below function because I am not in a loop for reason relating to layout. 我不能使用以下功能,因为由于布局原因我不在循环中。

the_post_thumbnail_url( ) 

I am just wondering whether I can get the thumbnail of the post via this function. 我只是想知道是否可以通过此功能获取帖子的缩略图。

$thumb_1 = get_post_meta( '40', 'thumb', true );      //40 is the post_id

I can pretty much retreive all other custom fields but, retrieving thumb seems to not work. 我几乎可以检索所有其他自定义字段,但是,检索thumb似乎不起作用。 Does anyone knows what is the "key" for the thumbnail image? 有谁知道缩略图的“关键”是什么?

Perhaps a better way to do this would be to use the function get_the_post_thumbnail_url(), which lets you pass in a post ID (and doesn't need to be in the loop: 也许更好的方法是使用函数get_the_post_thumbnail_url(),该函数可让您传递帖子ID(并且无需循环:

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/ https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

so $thumb = get_the_post_thumbnail_url(40); 所以$thumb = get_the_post_thumbnail_url(40);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM