wordp侧边栏问题与wp_list_categories显示没有类别

时间:2010-05-10 14:12:26

标签: wordpress wp-list-categories

所以我的wordpress安装。我试图在侧边栏中显示类别列表,但是遇到了wp_list_categories函数的问题。系统中有少数类别,但此功能只打印“无类别”。

无法弄清楚原因。

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

  1. 确保您要显示的每个类别中至少有1个帖子

  2. wp_list_categories应该在wordpress LOOP之外。您可能需要在LOOP代码之前提供侧边栏的代码。

答案 1 :(得分:0)

您正在使用正确的功能,但您需要为其调整参数。你到了

  

没有类别

只是因为WordPress分类中定义的类别没有分配帖子。

尝试将hide_empty参数传递给wp_list_categories( $args ); 1为true,将0传递给false。

wp_list_categories('hide_empty=0');

此示例将显示所有类别,无论其帖子数量如何。

参考wp_list_categories Codex页面获取更多帮助。

答案 2 :(得分:0)

使用内圈,使用 get_posts() 代替get_categories();

$cat_ID = 239;

$array =  get_posts('child_of'=> $cat_ID ,    'post_type'=> 'post');    $out='';
foreach ($array as $key=> $value) {
    $out .= '<li class="manual_posts"><a href="'.get_permalink($value->ID).'">'.$value->post_title.'</a></li>';
}
echo $out;
相关问题