2014-01-20 67 views
1

我想將我的類別圖像放入我的WooCommerce循環中,但從下面的代碼創建的數組似乎並未收集圖像URL。WooCommerce將圖像添加到類別循環

PHP

<?php $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'exclude' => '17,77')); ?> 

    <?php foreach($catTerms as $catTerm) : ?> 
    <ul> 
     <li><a href="<?php echo $catTerm->slug; ?>"><?php echo $catTerm->name; ?></a></li> 
    </ul> 
<?php endforeach; ?> 

會有人還跟幫助?

感謝

回答

3

試試這個,

<?php $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'exclude' => '17,77')); ?> 

    <?php foreach($catTerms as $catTerm) : 
      $wthumbnail_id = get_woocommerce_term_meta($catTerm->term_id,'thumbnail_id', true); 
      $wimage = wp_get_attachment_url($wthumbnail_id); 
    ?> 
    <ul> 
     <li><a href="<?php echo $catTerm->slug; ?>"><?php if($wimage!=""):?><img src="<?php echo $wimage?>"><?php endif;?><?php echo $catTerm->name; ?></a></li> 
    </ul> 
<?php endforeach; ?> 

希望其作品..

-1

我認爲你必須把UL標記出的foreach沒有重複的UL爲每個類別。

相關問題