在Woocommerce 3店面主题的主页上自定义排序类别

问题描述 投票:1回答:1

enter image description here我在主页面上显示了一个类别列表。我需要最后一个类别是第二个。我研究了排序选项,但它们并不合适。按名称,按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' );

但它只包括产品类别。

php wordpress sorting woocommerce custom-taxonomy
1个回答
1
投票

由于产品类别是自定义分类idids甚至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文件中。经过测试和工作。

© www.soinside.com 2019 - 2024. All rights reserved.