我在主页面上显示了一个类别列表。我需要最后一个类别是第二个。我研究了排序选项,但它们并不合适。按名称,按ID,随机。 ID为“50”的Сategory需要在列表中排在第二位。
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
将无法正常工作。相反,您将使用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文件中。经过测试和工作。