第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何從循環(huán)中排除帖子特色圖片?

如何從循環(huán)中排除帖子特色圖片?

PHP
波斯汪 2022-07-29 15:21:16
    在我的博客中,每篇文章都包含 2 張圖片:特色圖片 + 另一個(gè)附件圖片。我目前正在使用以下代碼調(diào)用特色圖片:echo get_the_post_thumbnail_url();然后使用以下一個(gè)嘗試獲取另一個(gè)附件圖像:$images = get_attached_media('image' );$image = reset($images );$ximage =  wp_get_attachment_image_src($image->ID,'medium');echo '' .$ximage[0] . '';問題是第二個(gè)代碼似乎以隨機(jī)方式獲得 a) 特色圖像或 b) 其他附件圖像。我想編輯第二個(gè)代碼,將其設(shè)置為忽略特色圖像,因此它始終會(huì)在所有帖子中回顯其他附件圖像。就像是:exclude="' . get_post_thumbnail_id( $post->ID ) . '";可能嗎?或者,是否可以告訴第二個(gè)代碼以獲取最新上傳的附件?
查看完整描述

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] . '">';


查看完整回答
反對(duì) 回復(fù) 2022-07-29
  • 1 回答
  • 0 關(guān)注
  • 96 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)