是否有一个插件或一些代码,在打开某个类别和所有产品后显示来自其他类别的产品。因为某些类别或子类别只有2-4个产品,所以我想用类似的其他类别产品填充页面。
例子:手套
手套页标题
2-4产品
然后是一些5-6产品的类靴
谢谢!
发布于 2018-07-31 18:14:36
简单的方法可能是创建多个类别--例如“服装”类别,并将手套和靴子都分配给它。更复杂的方法可能是使用查询生成一个清单。
$args = array(
'post_type' => 'product',
'posts_per_page' => 9,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'my-glove-category'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'my-boots-category'
)
)
);
$executedQuery = new WP_Query($args);
if ($executedQuery->have_posts()) {
while ($executedQuery->have_posts()) {
$executedQuery->the_post(); //increment the post pointer, getting us the next post in the list
echo '<h2>' . get_the_title() . '</h2>';
}
}
else {
echo 'No products were found.';
}
本例将获取my-glove-category
或my-boots-category
中的每个产品。如果你想按类别分类,那就开始变得更难了。
您还可以使用product_tag
作为这些查询的分类法,请参阅已安装的WooCommerce分类法和post类型。。
https://stackoverflow.com/questions/51619277
复制相似问题