Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Woocommerce 3店面主题主页上的自定义分类_Php_Wordpress_Sorting_Woocommerce_Custom Taxonomy - Fatal编程技术网

Php Woocommerce 3店面主题主页上的自定义分类

Php Woocommerce 3店面主题主页上的自定义分类,php,wordpress,sorting,woocommerce,custom-taxonomy,Php,Wordpress,Sorting,Woocommerce,Custom Taxonomy,我在主页上显示类别列表。我需要最后一类是第二类。我研究了排序选项,但它们不合适。 按姓名,按ID,随机id为“50”的С类别需要在列表中排名第二。 add_filter( 'storefront_product_categories_args', 'custom_storefront_product_categories'); function custom_storefront_product_categories( $args ) { $args['limit'] = 9;

我在主页上显示类别列表。我需要最后一类是第二类。我研究了排序选项,但它们不合适。 按姓名,按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;
}

编辑:

我尝试使用以下方法添加产品类别:

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
id
甚至
id
都不起作用。相反,您将使用
术语\u 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文件。已测试且有效。

您能重新表述您的问题吗?您希望如何在基于店面主题的网站的主页上重新排序类别?什么是
ids
?@KashifRafique,我想添加一个自定义排序顺序。标准不允许按正确顺序排序HI!我更新了一点问题,也许它变得更清晰了。很遗憾,此答案不合适。此答案回答了您最初的问题…如果您想根据产品类别的id对其进行排序,则需要使用
$args['orderby']='term_id'…您不能像尝试那样按自定义顺序对它们进行排序。现在您可以使用
$args['orderby']='term_order'
以“菜单顺序”对它们进行排序,就像在后端一样,您可以按自定义顺序对它们进行排序……感谢您的解答,但我认为您误解了这个问题。我正在尝试按照它们自己的顺序构建类别。$args['orderby']='term_id';-相同的$args['orderby']='id';