我使用wp_list_categories()
获取所有类别的列表并生成导航栏。除了字母顺序之外,有没有办法以特定的顺序对这些类别进行排序。
例如:连接,新闻和评论,问答,你好启动,启动101...
发布于 2017-02-09 09:56:56
大多数主题不使用类别的描述来做任何事情。我所做的简单的解决办法是在描述中使用数字。这里的第一个帖子目前有一些来自这里的jQuery黑客,它是不必要的。
我想您也可以添加自定义订单域。
只是
$categories = get_categories( array(
'orderby' => 'description',
'order' => 'ASC'
) );
发布于 2011-04-26 13:38:00
这是内置在wordpress_wp_list_categories
中的
wp_list_categories('orderby=name');
我想这会对你有帮助
发布于 2016-08-24 20:49:32
我这样做了,生成了几个术语列表。我稍后会按照我自己的顺序调用它。我是PHP初学者。
首先,我将每个类别术语的ID存储在一个不同的变量中:
$terms = get_terms('my_taxonomy', 'hide_empty=0');
foreach ( $terms as $term ) {
${$term->slug} = get_term_by('slug', $term->slug, 'product_cat');
${$term->slug.'_array'} = (array)${$term->slug};
${$term->slug.'_array_id'} =${$term->slug.'_array'}['term_id'];
};
然后,我为每个wp_list_categories()
创建了几个参数,使用这个变量排除了我想要的术语:
$args = array(
'taxonomy' => 'my_taxonomy',
'orderby' => 'name',
'show_count' => true,
'pad_counts' => false,
'hierarchical' => true,
'title_li' => '',
'hide_empty' => 0,
'show_option_all' => 'Show all',
'exclude' => array( $term1_array_id, $term2_array_id )
);
$args_1 = array(
'taxonomy' => 'my_taxonomy',
'orderby' => 'name',
'show_count' => true,
'pad_counts' => false,
'hierarchical' => true,
'title_li' => '',
'hide_empty' => 0,
'exclude' => array( $term3_array_id, $term4_array_id, $term1_array_id )
);
$args_2 = array(
'taxonomy' => 'my_taxonomy',
'orderby' => 'name',
'show_count' => true,
'pad_counts' => false,
'hierarchical' => true,
'title_li' => '',
'hide_empty' => 0,
'exclude' => array( $term1_array_id, $term4_array_id, $term5_array_id )
);
最后,我可以单独调用每个术语列表:
<ul>
<?php wp_list_categories( $args ); ?>
<?php wp_list_categories( $args_1 ); ?>
<?php wp_list_categories( $args_2 ); ?>
</ul>
https://stackoverflow.com/questions/517940
复制相似问题