How to change the number of product categories per row using WooCommerce(如何使用 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 个我使用过的产品:
To display 5 products per row I've used:
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 - 更改每行的产品数量
- WooCommerce - 条件标签
这篇关于如何使用 WooCommerce 更改每行的产品类别数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 WooCommerce 更改每行的产品类别数


- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01