我想在包含n个产品价格的循环中显示类别缩略图。这里的价格将从管理面板,其中金额将填补,产品类别缩略图将出现在一个页面上,其中有数量或大于数量的产品。所以请帮我写一个查询或任何其他解决方案,如果你可以给我。
我尝试了这个代码并获得成功。
//backend option for price
$value= get_option('price');
// the query
$args = array ('meta_query' => array(
array( 'key' => '_price',
'value' => $value,
'compare' => '>=',
'type' => 'NUMERIC',
),
),
'post_type' => 'product',
);
// The Query
$query = new WP_Query( $args ); ?>
<?php if ( $query->have_posts() ) : ?>
<!-- the loop -->
<?php $stack = array();?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php $a = $product->get_categories(); ?>
<?php if (!in_array($a, $stack)) : ?>
<li class="product-category">
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_id = $term->term_id;
$category_slug = $term->slug;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
echo '<img class="absolute category-image" src="'.$image.'">';
}
echo '<a href="' . get_term_link( $category_slug, 'product_cat' ) . '?min_price='.$value.'&max_price=1000500' . '">' . $category_name . '</a>';
?>