簡體   English   中英

在哪里將代碼添加到自定義庫短代碼

[英]Where to add code to custom gallery shortcode

我使用此處的信息http://ieg.wnet.org/2016/02/replacing-default-wordpress-gallery-shortcode/作為自定義畫廊簡碼的基礎,並嘗試創建此輪播滑塊https:// /www.jssor.com/demos/image-gallery.slider 問題是我不知道該如何實施。

直到那時圖像和所有內容都會在源代碼中顯示,但是之后沒有任何顯示。

   <div data-u="slides" style="cursor:default;position:relative;top:0px;left:0px;width:800px;height:356px;overflow:hidden;">

    <?php

foreach ( $images as $image ) {
    $thumbnail = wp_get_attachment_image_src($image->ID, 'homepage-thumb');
    $thumbnail = $thumbnail[0];
    $fullsize = wp_get_attachment_image_src($image->ID, 'service-page');
    $fullsize = $fullsize[0];
    $gallery .= "<div><img data-u='image' src='".$thumbnail."'><img data-u='thumb' src='".$fullsize."'></div>";  
    }
return $gallery;
?>       
         </div>

這可能很簡單,這遠遠超出了我的知識基礎。

您將返回值,而不是將其打印到網頁上。 使用echo而不是return 另外,請確保在循環的每次迭代中都echo它,以使您不僅打印一張圖像,而且還打印所有圖像。

<div data-u="slides" style="cursor:default;position:relative;top:0px;left:0px;width:800px;height:356px;overflow:hidden;">
<?php
    foreach ( $images as $image ) {
        $thumbnail = wp_get_attachment_image_src($image->ID, 'homepage-thumb');
        $thumbnail = $thumbnail[0];
        $fullsize = wp_get_attachment_image_src($image->ID, 'service-page');
        $fullsize = $fullsize[0];
        $gallery .= "<div><img data-u='image' src='".$thumbnail."'><img data-u='thumb' src='".$fullsize."'></div>"; 
        echo $gallery; 
    }
?>       
</div>

暫無
暫無

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

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