php - 获取当前子类别产品拇指 Woocommerce
问题描述
我试图在我的产品页面上获取特定父类别的子类别的产品类别拇指 - 我能够检索给定父类别的子类别的所有图像 - 但我只想显示属于子类别的图像的产品。现在它显示了所有父母孩子的产品上的所有图像。
如何设置它以便它只显示一个子类别,但仍然只显示给定的父类?
代码:
<?php
$catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'child_of'=>'74'));
foreach($catTerms as $catTerm) : ?>
<?php $thumbnail_id = get_woocommerce_term_meta( $catTerm->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id ); ?>
<li><img src="<?php echo $image; ?>" width="152" height="245"/><span><?php echo $catTerm->name; ?></span></li>
<?php endforeach; ?>
编辑:通过这样做解决:
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
if ( $term->parent == '174081' ) {
$category_name = $term->name;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
echo '<img src="'.$image.'">';
}
}
解决方案
推荐阅读
- audio - 如何用 ffmpeg 替换给定时间戳的音频?
- doctrine - 教义子查询语法
- javascript - 由于 CORS,HTTP Auth 请求在浏览器中失败,在 Node 中正常
- angular - 如何将数字值从角度传递给webapi
- javascript - javascript函数和javascript对象之间的主要核心区别是什么?
- javascript - javascript:使用我自己的确认框和功能确认功能
- jboss - 无法从 JBOSS 访问 CMS
- php - 从字符串中删除单引号和双引号
- oauth - 获取 Bearer 令牌后无法发出获取请求 - 401 错误“范围不足”
- rabbitmq - RabbitMQ Shovel 连接失败