I want to get my Category images into my WooCommerce loop below but the array that's created from my code below doesn't seem to collect the image URL.
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; ?>
Would someone be kind enough to assist?
Thanks
Try this,
<?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; ?>
Hope its works..
我认为您必须将UL标签放在foreach中,以免对每个类别重复UL。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.