我遇到了这个问题。我正在尝试按我希望的顺序对类别进行排序。我已经阅读了所有排序选项的WordPress文档。然而,对于如何选择类别并让它们按照我想要的方式流动,我没有任何倾向。
这就是法典所呈现的内容:
orderby (string)按字母顺序或按唯一类别ID对类别进行排序。默认值是按类别ID排序。有效值:
-ID
-name-默认值
-slug
-count
-term\\u group
order (字符串)类别的排序顺序(升序或降序)。默认值为升序。有效值:asc-默认值
然而,正如我所说,这对我没有帮助,因为我需要它们按照我选择的顺序显示。
下面是我目前正在实现的代码。这是我希望它们显示的顺序。
<?php
$args = array(
\'orderby\' => \'ID\',
\'order\' => \'ASC\',
\'include\' => \'5,6,7,8,29,9,10,11,12,13,14,15,16\'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo \'<li><a href="\' . get_category_link( $category->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name . \'</a>\' . \' \' . \'(\' . $category->count . \')\' . \'</li> \';
}
?>
SO网友:BethW
如果将参数更改为:\'orderby\' => \'include\'
$args = array(
\'orderby\' => \'include\',
\'order\' => \'ASC\',
\'include\' => \'5,6,7,8,29,9,10,11,12,13,14,15,16\'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo \'<li><a href="\' . get_category_link( $category->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name . \'</a>\' . \' \' . \'(\' . $category->count . \')\' . \'</li> \';
}