我希望有可能在每个Woocommerce类别的网格和列表视图之间进行选择。我找到了这个插件:https://nl.wordpress.org/plugins/woocommerce-grid-list-toggle/
但是,该插件适用于购物者选择是否在网格视图或列表视图中显示项目。我真正想要的是能够为后端的每个类别分配视图。
示例:
类别A显示为网格 类别B显示为列表
对此我不知所措。
答案 0 :(得分:2)
与this question类似,您需要过滤template_include
。您需要调用自定义存档模板archive-list-view.php
并将其保存在主题的woocommerce
文件夹中。显然,您可以将其命名为任何名称,您只需调整下面的代码即可。
文件夹结构:
/theme-folder/functions.php
/theme-folder/woocommerce/archive-list-view.php
在template_include
过滤器上,我们会检查我们是否在nussmylch
产品类别的术语存档中。如果是这样,我们将寻找并提供新模板。否则,使用标准模板。
编辑:使用了错误的WooCommerce功能is_product_taxonomy()
。需要is_product_category()
来检查特定类别。
add_filter( 'template_include', 'so_33615903_custom_category_template', 20 );
function so_33615903_custom_category_template( $template ) {
// check you are on the taxonomy archive for specific category
if ( is_product_category( 'nussmylch' ) ) {
$new_template = locate_template( array( 'woocommerce/archive-list-view.php' ) );
if ( '' != $new_template ) {
$template = $new_template ;
}
}
return $template;
}