Wordpress类别列出0个孩子的人口

时间:2015-07-13 06:17:02

标签: php wordpress wp-list-categories

我正在尝试显示所有已创建类别的列表,无论他们是否有帖子。我发现这个函数可以获得category-template.php中的类别列表。我不确定应该对此功能进行哪些编辑以获得我所需的结果。

function get_the_category( $id = false ) {
$categories = get_the_terms( $id, 'category' );
if ( ! $categories || is_wp_error( $categories ) )
    $categories = array();

$categories = array_values( $categories );

foreach ( array_keys( $categories ) as $key ) {
    _make_cat_compat( $categories[$key] );
}


return apply_filters( 'get_the_categories', $categories );
}

在这里漫游,我看过Scott B.的手动方式here但不幸的是我无法完全理解它。

1 个答案:

答案 0 :(得分:1)

这对我有用:

 <ul>
  <?php $args = array(
  'orderby' => 'name',
  'order' => 'ASC'
);
$categories = get_categories($args);
foreach ( $categories as $category ) {?>
    <li><?php echo '<a href="' . get_category_link( $category->term_id ) . '" >' . $category->name.'</a>'; ?></li>
<?php } ?> 
</ul>