英文:
Create a Woocommerce custom template with product filter
问题
I can provide the translation of your code snippet:
我正在创建一个自定义模板,在其中我想要显示产品信息并带有一些筛选器。
这是我用来显示产品循环的代码:
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'product_cat' => $product_category
);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()):
$loop->the_post();
wc_get_template_part('content', 'product');
endwhile;
} else {
echo __('No products found');
}
wp_reset_postdata();
?>
</ul>
Regarding your question about creating filters for users to choose product attributes like colors and tags, you can achieve this by using WooCommerce's built-in filtering and attributes functionality. You'll need to define attributes for your products in the WooCommerce settings, assign attributes to each product, and then create filters on your website to allow users to select these attributes for filtering.
If you need more specific guidance on implementing filters, please provide additional details, and I can assist you further.
英文:
I'm creating a custom template where I want to show the product feed with some filters.
This is the code I'm using to display the product loop:
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'product_cat' => $product_category
);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()):
$loop->the_post();
wc_get_template_part('content', 'product');
endwhile;
} else {
echo __('No products found');
}
wp_reset_postdata();
?>
</ul>
How can I create the filters to let the user choose products attributes? (for ex. colors, tag)
答案1
得分: 1
“Filter Everything”插件应该能正常工作。它允许您基于类别、标签、自定义分类、产品属性、acf字段等轻松创建筛选器。
我相信您可以使用短代码或在您想要筛选器的地方放置一个小部件,比如侧边栏,并设置包含您循环的容器。
您可以复制和自定义模板部分,如单选按钮布局或复选框布局,并将每组筛选器应用于您想要的布局。
例如,您可以为类别设置单选按钮,为标签设置复选框,为尺寸设置下拉菜单,为颜色设置样品,全部按您的样式设计。
英文:
The Filter Everything plugin should work. It allows you to easily create filters based on categories, tags, custom taxonomies, product attributes, acf fields, etc.
I believe you can use a shortcode or drop a widget where you want the filters, like in the side bar, and set what container has your loop.
You can copy and customize the template parts, like the radio button layout or the checkbox layout, and apply each set of filters the layout you want.
For instance you can set up radio buttons for category and checkboxes for tags, a drop down for size, and swatches for color, all styled how you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论