如何使用WooCommerce更改每行产品类别的数量 [英] How to change the number of product categories per row using WooCommerce
问题描述
我正在使用Woocommerce设置在初始商店页面上显示类别缩略图,然后在其中显示产品及其缩略图。
I'm using Woocommerce settings to show categories thumbnail on the initial shop page and then products and their thumbnails within them.
我想要该初始类别页面每行显示3个缩略图,产品页面每行显示5个类别。
I want to have that initial category page to display 3 thumbnails per row and the products page to show 5 categories per row.
每行显示5个产品:
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 5;
}
}
这会更改类别页面上每行的缩略图,并且
This changes the thumbnails per row on the category page AND on the shop page too.
有人知道如何将类别页面更改为每行3个缩略图,并在商店页面上每行维护5种产品吗?
Does anyone know how I can change the categories page to 3 thumbnails per row and maintain 5 products per row on shop page?
推荐答案
使用 WooCommerce条件标签,将帮助您实现这一目标。我已经更改了您的代码:
Using WooCommerce conditionals tags, will help you to achieve that. I have changed your code:
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
if ( is_product_category() ) {
return 3;
} else { // for other archive pages and shop page
return 5;
}
}
}
这段代码您的活动子主题或主题的function.php文件上的
建议:有时,有必要更改某些CSS规则,以获得正确的显示。
Advice: Sometimes, is necessary to change some css rules, to get the correct display per row.
WooCommerce条件标签的用法:
定位到商店页面存档:
if ( is_shop() ) {
// return the number of items by row
}
要定位产品标签存档:
if ( is_product_tag() ) {
// return the number of items by row
}
定位所有产品档案除了产品类别存档(在开头添加了 !
):
if ( !is_product_category() ) {
// return the number of items by row
}
您可以还定义一些特定的类别或标签 (请参见文档)。
And you can also define some particular categories or tags (see the documentation for that).
参考文献:
References:
- WooCommerce - Change number of products per row
- WooCommerce - Conditionals tags
这篇关于如何使用WooCommerce更改每行产品类别的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!