2015-06-15 56 views
0

我如何能实现与下面的现有代码两件事情:Bxslider,自定义字段和WordPress的

  1. 取出空值,因为这些是出口bxslider已断开链接
  2. 出于某种原因,两个项目正在显示寻呼机中每个图像的版本。任何人都可以看到为什么以及我如何阻止这些重复。

    <ul class="bxslider"> 
    <?php 
    $images = get_post_meta(get_the_ID() , "images", true); 
    $images = unserialize($images); 
    
    // Read into array 
    
    foreach($images as $image) 
        { 
        $ar[] = array(
         "order" => $image['order'], 
         "img_id" => $image['image_id'], 
         "desc" => $image["desc"] 
        ); 
        } 
    
    // Sort array by order 
    
    asort($ar); 
    
    // Output data for Galleria 
    
    foreach($ar as $item) 
        { 
        $image_id = $item['img_id']; 
        $media_med = wp_get_attachment_image_src($image_id, "medium", false); 
        $media_full = wp_get_attachment_image_src($image_id, "full", false); 
        echo "<li><img data-title='" . $item["desc"] . "' data-big='" . $media_full[0] . "' src='" . $media_med[0] . "'></li>"; 
        } 
    
    ?> 
    </ul> 
    <div id="bx-pager"> 
    <?php 
    $images = get_post_meta(get_the_ID() , "images", true); 
    $images = unserialize($images); 
    
    // Read into array 
    
    foreach($images as $image) 
        { 
        $ar[] = array(
         "order" => $image['order'], 
         "img_id" => $image['image_id'], 
         "desc" => $image["desc"] 
        ); 
        } 
    
    // Sort array by order 
    
    asort($ar); 
    
    // Output data for Galleria 
    
    foreach($ar as $item) 
        { 
        $image_id = $item['img_id']; 
        $media_med = wp_get_attachment_image_src($image_id, "medium", false); 
        $media_full = wp_get_attachment_image_src($image_id, "full", false); 
        echo "<a href='' data-slide-index='0'>"; 
        echo "<img src='" . $media_med[0] . "'>"; 
        echo "</a>"; 
        } 
    
    ?> 
    </div> 
    

回答

1

首先,你可以在$ AR阵列上运行array_filter()删除假/空值。

接下来,你可能并不需要这一行

$media_full = wp_get_attachment_image_src($image_id, "full", false); 

你可以把它注释掉,它不会对页面上的任何影响。

+0

感谢您的支持。我对array_filter没有任何经验 - 你能在我的代码的ocntext中包含一个例子吗? – dmt

+0

就在排序数组之前。 array_filter($ ar); asort($ ar); – DoctorFox