1 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
這將在以下兩種情況下起作用:
1)。有一張?zhí)厣珗D片,還有第二張圖片。
2)。沒有特色圖片,但有另一張圖片
如果內(nèi)容中有多個(gè)圖像,則可能需要修改此代碼以考慮其他圖像 - 但是,key($images)可能只是獲取它找到的第一個(gè)鍵。
// Get all the images
$images = get_attached_media('image');
// Get the featured image
$featured_image_id = get_post_thumbnail_id();
// If there is a featured image
if ( has_post_thumbnail() ) {
// Remove the featured image from the images array
unset($images[ $featured_image_id ] );
}
// Set your ximage var to get the src using the key from the $images array - which is the 2nd image ID.
$ximage = wp_get_attachment_image_src( key($images),'medium');
// Echo it out.
echo '<img src="' . $ximage[0] . '">';
- 1 回答
- 0 關(guān)注
- 96 瀏覽
添加回答
舉報(bào)