2014-03-28 77 views
0

不知道爲什麼會發生這種情況。以下腳本使用特定模板顯示所有頁面的標題,鏈接和自定義元。Wordpress複製信息

由於某種原因它複製了信息。

在線例如:http://greenleavesmarketing.co.uk/sherif/prices/

腳本:

<?php // Display list of pages using the template page-landing.php 


    $product_pages_args = array(
     'meta_key' => '_wp_page_template', 
     'meta_value' => 'page-landing.php', 
     'depth' => -1, 
     'hierarchical' => 0, 
    ); 

    $product_pages = get_pages($product_pages_args); 


    echo '<table class="price-table"> 
      <thead> 
       <tr> 
        <td>Dental Procedure</td> 
        <td>Cost</td> 
       </tr> 
      </thead>'; 

     foreach ($product_pages as $product_page) { 

      echo ' 
      <tr> 
       <td> 
        <a href="'.get_permalink($product_page->ID).'">'.$product_page->post_title .'</a> 
       </td> 
       <td>'; ?> 
      <?php 
      $custom_metabox = get_post_meta($product_page->ID,'_custom_meta',TRUE); 

       if($custom_metabox['landing-para']!=false) {   
        echo $custom_metabox['landing-para']; 
       } else { 
        echo 'Please contact us for a free consultation.';  
       } 

       echo '</td> 
      </tr>'; 
     } 

    echo '</table>'; wp_reset_query(); ?> 
+0

是否存在來自get_pages的數據中的重複項()? – derekshull

+0

你可以顯示「$ product_pages」的內容(作爲數組)嗎? –

+0

嘗試過兩種方法,仍然沒有運氣:( – leannekera

回答

-1

這並不解決根本問題,但如果所有$product_page->post_title值是唯一的,你可以將它們存儲在數組中,當您瀏覽如果該值已存在,則返回continue

// create a dummy array to store $product_page->post_title values: 
    $post_titleArr = array(); 

    foreach ($product_pages as $product_page) { 
     if (in_array($product_page->post_title, $post_titleArr)) continue; // skip this iteration for dupe. 
     $post_titleArr[] = $product_page->post_title; // not a dupe - add it to the array. 

     // continue your code... 
     echo ' 
+0

非常感謝你這麼多! – leannekera