我想将我的分类图像放到下面的WooCommerce循环中,但是从我下面的代码创建的数组似乎并没有收集图像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; ?>
有人会善意帮忙吗?
由于
答案 0 :(得分: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 :(得分:-1)
我认为你必须将UL标签放在foreach之外,不要为每个类别重复UL。