亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試獲取附件 url 后未??定義的 url

嘗試獲取附件 url 后未??定義的 url

PHP
慕容森 2021-11-05 15:22:14
在 WordPress 的后端,我有一個選項,用戶可以在其中添加多個圖像。然后這些圖像將explode顯示在 中li,無論如何這就是目標。但是我在 上收到未定義的索引 url $result .= $attachmentImage ? $attachmentImage['url'] : '';。標記:$image = shortcode_atts(    array(        'image' => 'image',    ),     $atts );$image_ids = explode(',',$image['image']);$result = "<div class='imageCarousel'>";$result .= "<div class='imageCarousel__container justify-content-center'>";$result .= "<ul>";foreach( $image_ids as $image_id ){    $result .='<li>';    $result .= 'test'. $image_id;    $attachmentImage = wp_get_attachment_image_src( $image_id, 'full' );    $result .= $attachmentImage ? $attachmentImage['url'] : '';    $result .='</li>';}$result .= "</ul>";$result .= "</div>";$result .= "</div>";return $result;Avar_dump($attachmentImage)什么都不返回?
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

根據代碼,在調用短代碼時需要添加有效的圖像ID,以逗號分隔。


喜歡。


//image1 is name of shortcode, and 10,11,12 is valid id of image

echo do_shortcode('[image1 image=10,11,12]');

您收到 Receiving 'undefined index url' 因為 wp_get_attachment_image_src 返回一個包含以下元素的數組。


[0] => url

[1] => width

[2] => height

[3] = >

因此,在代碼中,您需要通過 $attachmentImage['0'] 獲取圖像 url。


//$attachmentImage['0'] - will display the url of image

$result .= $attachmentImage ? $attachmentImage['0'] : '';


查看完整回答
反對 回復 2021-11-05
  • 1 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號