【发布时间】:2019-01-08 04:45:21
【问题描述】:
是否有插件或一些代码在打开某个类别后显示所有产品以显示其他类别的产品。因为某些类别或子类别只有 2-4 个产品,我想用其他类别的产品来填充页面。
例如:手套
手套页面标题
2-4 个产品
然后一些类别的靴子有 5-6 种产品
谢谢!
【问题讨论】:
标签: wordpress plugins woocommerce categories product
是否有插件或一些代码在打开某个类别后显示所有产品以显示其他类别的产品。因为某些类别或子类别只有 2-4 个产品,我想用其他类别的产品来填充页面。
例如:手套
手套页面标题
2-4 个产品
然后一些类别的靴子有 5-6 种产品
谢谢!
【问题讨论】:
标签: wordpress plugins woocommerce categories product
执行此操作的简单方法可能是创建多个类别 - 例如“服装”类别并将手套和靴子分配给它。更复杂的方法可能是使用WP_Query 来生成列表。
$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 作为这些查询的分类,请参阅the installed taxonomies and post types for WooCommerce.
【讨论】: