php - Woocommerce 3 Storefront 主题主页上的自定义排序类别
问题描述
我在主页上显示类别列表。我需要最后一个类别排在第二位。我研究了排序选项,但它们不适合。按名称,按 ID,随机。ID 为“50”的类别需要在列表中排在第二位。
add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories');
function custom_storefront_product_categories( $args ) {
$args['limit'] = 9;
$args['columns'] = 3;
$args['orderby'] = 'id'; // sort by id category
return $args;
}
编辑:
我尝试使用以下方法添加产品类别排序 ID:
function custom_storefront_category_filtering( $args ) {
$args['ids'] = '16,50,17,18,19,20,21,22,23'; // need such a sequence of categories
return $args;
}
add_filter('storefront_product_categories_shortcode_args','custom_storefront_category_filtering' );
但它只包括产品类别。
解决方案
由于产品类别是自定义分类法id
,ids
甚至ID
不起作用。相反,您将使用which 是该上下文中参数term_id
的适当参数值。orderby
为什么?因为我们的目标不是帖子 ID ,而是术语 ID。
所以在你的过滤器钩子中:
add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories');
function custom_storefront_product_categories( $args ) {
$args['limit'] = 9;
$args['columns'] = 3;
$args['orderby'] = 'term_id';
return $args;
}
代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。
推荐阅读
- xcode - 命令 /usr/bin/codedesign 在 Xcode 11 上失败,退出代码为 1
- vim - 有人可以阐明为什么 softtabstop 不起作用以及其他理解上的差距吗?
- c# - 试图将 VBA 数据库声明转换为 C#
- javascript - Import non-ES6 module into webpack
- racket - 需要 2 个参数,但只找到 1 个
- python - I want to load a template from the templates folder but I get an error that says the included URLconf does not appear to have any patterns in it
- .net - LDAP Search Filter Syntax (ONLY) to Identify Objects in a Specific OU (AD)
- javascript - JavaScript Onclick phone/email validation function not working
- traits - How can I fix "actix_web::handler::AsyncFactory<_, _> is not implemented" error?
- google-apps-script - 当我重新部署我的插件时,onEdit 功能代码没有改变