我有这段代码用于在移动主题中将新产品显示为hscroll 但我不想显示ID为1230的类别产品
我通过添加一些代码来添加思考,例如:$products->category-> != 1230
请指导
<?php
// new arrivals products
$new_args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'orderby' =>'date',
'order' => 'DESC'
);
$products = new WP_Query( $new_args );
?>
<?php if ( $products->have_posts() ) { ?>
<div class="title-intro content-block-title"><?php _e( 'New Arrivals', 'woomobify' ); ?></div>
<div class="product-hscroll swiper-container swiper-init" data-auto-height="true" data-free-mode="true" data-slides-per-view="auto">
<div class="swiper-wrapper">
<?php while ( $products->have_posts() ) : $products->the_post(); global $product; ?>
<div class="swiper-slide">
<div class="card">
<div class="card-content">
<a href="<?= get_the_permalink(); ?>">
<?php
if ( has_post_thumbnail($products->post->ID) ) {
echo get_the_post_thumbnail( $products->post->ID, 'shop_catalog' );
} else {
echo '<img src="'.wc_placeholder_img_src().'"/>';
} ?>
</a>
<div class="title"><?php the_title(); ?></div>
<div class="item-text product-price">
<span class="price"><?= wc_price( $product->get_price() ); ?></span>
</div> </div> </div>
<?php endwhile; ?>
答案 0 :(得分:0)
我认为您正在寻找的解决方案描述于
https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/
或者为了使操作更简单,请使用下一个参数检索所有产品,除非产品属于(id)类别1230
$args = array(
'posts_per_page' => -1,
'orderby' =>'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => array('1230'),
'operator' => 'NOT IN')));