在循环中显示产品类别缩略图,在woocommerce中有n个产品价格

时间:2015-05-20 08:29:55

标签: php wordpress woocommerce categories

我想在循环中显示具有n个产品价格的类别缩略图。 此处n价格将从管理面板中放入金额将填充,且产品类别缩略图将显示在具有该金额或大于该金额的产品的页面上。 所以如果你能给我,请帮我写一个查询或任何其他解决方案。

1 个答案:

答案 0 :(得分:0)

我尝试了这段代码并获得了成功。

//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>';

?>