2017-09-24 72 views
0

我想獲得WooCommerce中的所有產品並製作帶有主題的滑塊。無法獲得WooCommerce中的所有產品

所以我在function.php代碼:

function zf_theme_home_slide() { 
    $args = array(
     'post_type' => 'product',  /* post type */ 
     'post_status' => 'publish', /* post montasher shode */ 
     'orderby' => 'date',   /* moratab sazi bar asas tarikh — date , ID , author , type , name , title , parent , rand , comment_count — */ 
     'order' => 'DESC'    /* moratabsazi Soudi ya nozooli — DESK = Nozooli , ASC = Soudi */ 
    ); 
    $post_query = new WP_Query($args); 
    ob_start(); 
    var_dump($post_query); 
    if($post_query->have_posts()) : 
     ?> 
     <div class="flexslider" > 
      <ul class="slides"> 
       <?php while ($post_query->have_posts()) : 
        $post_query->the_post(); 
        // if(get_field('slide_hn_theme')){ 
         $hn_permalink = get_the_permalink(); 
         $hn_title = get_the_title(); 
         $hn_thumbnail = get_the_post_thumbnail_url(); 
         ?> 
         <li class="product-thumbnail-outer"> 
          <div> 
           <a class="slide_item" href=" <?php echo $hn_permalink ?> "><img width="300" height="140" src=" <?php echo $hn_thumbnail ?> " /> 
            <span class="slide_items_details"> 
             <span class="slide_item_title"><?php echo $hn_title ?> </span> 
             <span class="slide_item_creat"> <?php echo $hn_webcreate ?> </span> 
            </span> 
           </a> 
          </div> 
         </li> 
         <?php 
        // } 
       endwhile; 
       ?> 
      </ul> 
     </div> 
     <?php 
    endif; 
    wp_reset_postdata(); 
    return ob_get_clean(); 
} 

add_shortcode('zf_theme_home_slide','zf_theme_home_slide'); /* pro_Des Copy to Page for Show Blogs */ 

但我只得到三種產品。我不知道爲什麼我的代碼只返回所有產品的三種產品。我該如何解決它?

+0

加'回聲「

';print_r($post_query->request);echo '
」的輸出;'有問題,還請確保您有更多的產品發佈比3。 – Noman

+0

添加arg'posts_per_page'=> -1 –

+0

我使用了var_dump($ post_query);並且只顯示3歷時產品 –

回答

0

與下面的代碼,你需要添加僅爲頁數限制的職位嘗試..

$args = array(
    'post_type' => 'product',  /* post type */ 
    'post_status' => 'publish', 
    'orderby' => 'date',   
    'posts_per_page' => -1, 
    'order' => 'DESC'    
); 
+0

當我用「」 posts_per_page「」我得到HTTP錯誤500 –

+0

有一個語法錯誤,請檢查我的鱈魚enow –

+0

我固定的,但我得到的HTTP錯誤500 –

相關問題