我已经做了一个产品展示页面使用宇商务插件。我想排序的产品类别的基础上,我可以怎么做呢?我可以在下拉列表中显示类别,但不能根据类别进行排序
这是我到目前为止所做的。
<?php/*Template Name: Products */?>
<?php get_header();
$args = array(
'post_type' => 'product',
'meta_key' => $meta_key,
'orderby' => 'meta_value_num',
'order' => $order,
'taxonomy'=> 'product_cat',
// 'tax_query' => array(
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'women',
// ),
// )
);
?>
<div class="container big">
<!-- <div class="row"> -->
<!-- Category Selector -->
<?php
$result=new WP_Query($args);
?>
<!-- category -->
<select class="event-dropdown">
<option value=""><?php echo esc_attr(__('Select category')); ?></option>
<?php
$categories = get_categories($args);
foreach ($categories as $category) {
$option .= '<option value="'.$category->slug.'">';
$option .= $category->cat_name;
$option .= '</option>';
}
echo $option;
?>
</select>
<!-- category end -->
<?php
$total = $result->post_count;
if ( $i == 0 ) echo '<div class="row up">';
// the Loop
if($result->have_posts()){
while($result->have_posts()){
$result->the_post();
$default_img = '<img src="' . site_url() . '/wp-content/uploads/2020/06/noimage.jpg' . '"/>';
$img = ( get_the_post_thumbnail() ) ? get_the_post_thumbnail() : $default_img;
$price= get_post_meta( get_the_ID(), '_regular_price', true);
?>
<div class="col-md-4">
<div class="idv-product">
<div class="card"><a href="<?php the_permalink();?>"><?php echo $img?></a></div>
<div class="text-center"><?php the_title();?></div>
<hr>
<!-- <div class="test text-center"> <?php echo $price; ?></div> -->
<div class="test text-center"><?php echo woocommerce_template_single_price();?></div>
</div>
</div>
<?php $i++;
if($i== $total){
echo '</div>';
} else {
if($i % 3 ==0){ echo'</div><div class="row up">'; }
}
}
/* Restore original Post Data */
}
?>
<!-- old code -->
</div><!-- constainer -->
<?php get_footer();?>
如何根据所选类别显示产品(过帐)?
结束