問題描述
我使用 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 更改每行的產品類別數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!