我刚刚在我的函数中注册了以下代码
add_action( 'init', 'create_resources_taxonomies', 0 );
function create_resources_taxonomies() {
$labels = array(
'name' => _x( 'cat2', 'taxonomy general name' ),
'singular_name' => _x( 'cat2', 'taxonomy singular name' ),
'search_items' => __( 'Search category' ),
'all_items' => __( 'All category' ),
'parent_item' => __( 'Parent category' ),
'parent_item_colon' => __( 'Parent category:' ),
'edit_item' => __( 'Edit category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New category Name' ),
'menu_name' => __( 'genre' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
register_taxonomy( 'genre', array( 'resources' ), $args );
}
我希望在侧边栏中找到类别列表,所以我在侧栏中添加了以下代码
<?php
$taxonomy = 'genre';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
但我只是得到“没有类别”的文字。我的代码出了什么问题?
答案 0 :(得分:0)
您的代码看起来正确,我猜你的类别是空的!我对么?如果是,请将以下代码添加到'title_li'
'hide_empty' => 0,
所以你的代码应该是这样的
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'hide_empty' => 0,
'title_li' => $title