簡體   English   中英

如何使用get_post_meta在wordpress中獲取縮略圖

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

我有一個wordpress網站,我正在嘗試獲取帖子的縮略圖(又稱特色圖片)。 我不能使用以下功能,因為由於布局原因我不在循環中。

the_post_thumbnail_url( ) 

我只是想知道是否可以通過此功能獲取帖子的縮略圖。

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

我幾乎可以檢索所有其他自定義字段,但是,檢索thumb似乎不起作用。 有誰知道縮略圖的“關鍵”是什么?

也許更好的方法是使用函數get_the_post_thumbnail_url(),該函數可讓您傳遞帖子ID(並且無需循環:

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

所以$thumb = get_the_post_thumbnail_url(40);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM