首页 > 解决方案 > Empty categories are not listed - wordpress

问题描述

I want to show empty categories in the list.What is wrong with this code?

function cat_list(){
    $args = array(
    'hide_empty' => 0,
    'orderby' => "name",
    'order' => "ASC" );
    $categories = get_categories(args);
    foreach($categories as $category){
    echo '<li><a href="' .get_category_link($category->term_id) . '"> '. $category->name . '</a></li>';

  }
}

标签: wordpress

解决方案


You have a missing $ while passing arguments to get_categories. Here's the fixed one.

function cat_list(){
    $args = array(
    'hide_empty' => 0,
    'orderby' => "name",
    'order' => "ASC" );
    $categories = get_categories($args);
    foreach($categories as $category){
    echo '<li><a href="' .get_category_link($category->term_id) . '"> '. $category->name . '</a></li>';

}

推荐阅读