我的最終目標(biāo)是建立一個(gè)圖像庫(kù),點(diǎn)擊該庫(kù)即可連結(jié)到外部網(wǎng)站。這需要透過(guò)高級(jí)自訂欄位來(lái)完成,因此我製作了一個(gè)中繼器,其圖像和連結(jié)位於同一行:
link1 | cover_image1 link2 | cover_image2
現(xiàn)在我正在將此程式碼插入網(wǎng)頁(yè)內(nèi)的文字編輯器。我還從這裡導(dǎo)入了一些短代碼,這允許我使用 %ROW% 作為迭代器。
“attachments”是父轉(zhuǎn)發(fā)器,“l(fā)ink”和“cover_image”是子轉(zhuǎn)發(fā)器。
[acf_repeater field="attachments"] external url = [acf field ='attachments_%ROW%_link'] image url = [acf field ='attachments_%ROW%_cover_image'] <a href =[acf field ='attachments_%ROW%_link'] > <img src = [acf field ='attachments_%ROW%_cover_image'] width="300" height="214" /> </a> [/acf_repeater]
網(wǎng)頁(yè)呈現(xiàn)如下:
損壞的圖像包含以下程式碼:
<img src="[acf" field="attachments_0_cover_image" ]="" width="300" height="214">
我認(rèn)為 <img>
中的 [acf field ='attachments_%ROW%_cover_image'] 並未完全解析到 url,因?yàn)?external url = 和 image url = 都呈現(xiàn)正確的 url。
Wordpress 在儲(chǔ)存後也會(huì)將我的程式碼轉(zhuǎn)換為此程式碼,所以它可能是個(gè)語(yǔ)法錯(cuò)誤?
[acf_repeater field="attachments"] external url = [acf field = attachments_%ROW%_link] image url = [acf field = attachments_%ROW%_cover_image] <a href="[acf"> <img src="[acf" width="300" height="214" /> </a> [/acf_repeater]
我不確定如何正確地將 [acf field ='attachments_%ROW%_cover_image'] 轉(zhuǎn)換為 <img>
中的 url,我可以使用一些有關(guān)正確語(yǔ)法的幫助。非常感謝您的幫忙!
每個(gè) Arian 屬性的 html:
<div class="fl-module fl-module-rich-text fl-node-5d4926759d7aa" data-node="5d4926759d7aa"> <div class="fl-module-content fl-node-content"> <div class="fl-rich-text"> <p>Agenda: <a href="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/cute-cat-photos-1593441022.jpg?crop=0.669xw:1.00xh;0.166xw,0&resize=640:*">https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/cute-cat-photos-1593441022.jpg?crop=0.669xw:1.00xh;0.166xw,0&resize=640:*</a></p> <p>Video Links: <a href="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/cute-cat-photos-1593441022.jpg?crop=0.669xw:1.00xh;0.166xw,0&resize=640:*"></a></p> <p>Thumbnails: <a href=""></a></p> <p></p> <p>external url = https://www.youtube.com/watch?v=uHKfrz65KSU<br> image url = http://wordpress.local/wp-content/uploads/Thumbnail_1.png</p> <p><a href="[acf" field="attachments_0_link" ]=""><br> <img src="[acf" field="attachments_0_cover_image" ]="" width="300" height="214"><br> </a></p> <p><br></p> <p>external url = https://www.youtube.com/watch?v=X2lIovmNsUY<br> image url = http://wordpress.local/wp-content/uploads/Thumbnail_2-1.png</p> <p><a href="[acf" field="attachments_1_link" ]=""><br> <img src="[acf" field="attachments_1_cover_image" ]="" width="300" height="214"><br> </a></p> <p><br></p> <p>external url = https://www.youtube.com/watch?v=hDJkFLnmFHU<br> image url = http://wordpress.local/wp-content/uploads/Thumbnail_3-1.png</p> <p><a href="[acf" field="attachments_2_link" ]=""><br> <img src="[acf" field="attachments_2_cover_image" ]="" width="300" height="214"><br> </a></p> <p><br></p> </div> </div> </div>
不是 WordPress 人員,但似乎 WordPress 會(huì)阻止使用 html 屬性中的參數(shù)擴(kuò)充/執(zhí)行短程式碼,如果您可以將 php 程式碼放在那裡,也許這可以作為解決方法:
實(shí)際上我發(fā)現(xiàn)了對(duì)此的評(píng)論:
在此處
所以這也可能有效:
或沒有短代碼引號(hào):
我能想到的最後一個(gè)選擇是建立無(wú)參數(shù)的短程式碼,如下所示:
function acflink_shortcode() { return do_shortcode("[acf field ='attachments_%ROW%_link']"); } add_shortcode('acflink', 'acflink_shortcode'); function acfimage_shortcode() { return do_shortcode("[acf field ='attachments_%ROW%_cover_image']"); } add_shortcode('acfimage', 'acfimage_shortcode');
然後在編輯器中使用,例如: