显示分页并排除类别


Show pagination and exclude category

所以,我试图从woocommerce的特定类别中显示项目:

到目前为止我写的是:

<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => '',  'orderby' => 'date', 'order' => 'DESC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; 
?>
<div class="content"> Content </div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>  

product_cat为空时,显示所有项目。我想加入"排除类别"

例如,我想显示"no_good"类别中除项目外的所有项目。

有人能帮我一下吗?

另外,我如何添加分页到这个?

谢谢!

product_cat是您的自定义分类法吗?如果是,那么你需要修改你的$args与税务查询:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 10,
    'orderby' => 'date',
    'order' => 'DESC',
    'tax' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'name',
            'terms' => array('no_good'),
            'operator' => 'NOT IN',
        ),
    ),
);
...

假设"no_good"是product_cat名称。如果没有字段,请调整字段

关于分页部分,请参阅有关分页的法典文章