2017-07-21 172 views
1

所以這是我爲視覺作曲家製作的簡碼。它購物我的woocommerce類別,但我想不出我會如何阻止它顯示子類別,只顯示主要類別。僅顯示WooCommerce主要產品類別

任何想法?

感謝

<?php //wp_enqueue_script(array('jquery', 'owl-carousel')); 
    $count = 0; 
    $term_args = array('hide_empty' => $empty , 'number' => $num , 'order_by' => $sort , 'order' => $order); 
    //if($cat) $query_args['category_name'] = $cat; 
    //echo balanceTags($cat); exit('sssss'); 
    $terms = get_terms('product_cat', $term_args) ; 
    //printr($terms); 
    ob_start() ;?> 

<section id="featureCat2" class="row contentRowPad"> 
<div class="container"> 
    <h3 class="heading"><?php echo balanceTags($title); ?></h3> 
<?php if (! empty($terms) && ! is_wp_error($terms)):?> 
    <div class="row m0"> 

    <?php foreach ($terms as $term) : 
      $meta = _WSH()->get_term_meta('_sh_product_cat_settings', $term->term_id);//printr($meta); 
    ?> 

     <div class="col-sm-3"> 
      <div class="row category2 text-center"> 
       <div class="row m0 imgHov"> 
       <?php $thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); ?> 
        <?php echo wp_get_attachment_image($thumbnail_id, '292x198'); ?> 
        <div class="hovArea row m0"> 
         <a href="<?php echo esc_url(get_term_link($term)); ?>"><?php esc_html_e('shop now ', 'furniture');?><i class="fa fa-caret-right"></i></a> 
        </div> 
       </div> 
       <div class="row m0"> 
        <h5 class="heading"><?php echo balanceTags($term->name);?></h5> 
        <ul class="list-unstyled black-color"> 
        <?php $query = get_posts(array('showposts'=>4, 'post_type'=>'product', 'product_cat'=>$term->slug, 'order'=>'DESC')); //printr($query);?> 
         <?php if($query) 
         foreach($query as $qu): ?> 
          <li><a href="<?php echo get_permalink($qu->ID); ?>" title="<?php echo get_the_title($qu->ID); ?>"><?php echo get_the_title($qu->ID); ?></a></li> 
         <?php endforeach; ?> 
        </ul> 
       </div> 
      </div> 
     </div> 

     <?php endforeach;?> 

    </div> 

    <?php endif;?> 

</div> 
</section> 

<?php return ob_get_clean(); 

回答

1

要顯示你需要添加'parent'論點這樣,只有主要產品類別:

$term_args = array(
    'parent' => 0, 
    'hide_empty' => $empty , 
    'number' => $num , 
    'order_by' => $sort , 
    'order' => $order, 
); 

$terms = get_terms('product_cat', $term_args); 

然後,你將只能得到主要產品類別沒有子類別。

+1

請注意,如果您的新內容已從您的所有答案中編輯出來,請注意您應該怎麼做。有關詳細信息,請參閱:https://meta.stackoverflow.com/questions/352638/is-it-可以接受的包括一個鏈接到幫助中心在一個無關回答 – NathanOliver

+0

完美謝謝你!只是想知道,這些術語是否在woocommerce文檔中的某個地方用於將來的參考?乾杯 – JPWeb

+0

@JPWeb所有這些都與** WordPress **自定義分類法和[WP_Query類參考](https://codex.wordpress.org/Class_Reference/WP_Query)有關... – LoicTheAztec

相關問題