wordpress sidebar issue with wp_list_categories showing NO Categories

故事扮演 提交于 2019-12-12 01:30:05

问题


So on my wordpress install. I am trying to display category list in the sidebar but having issue with wp_list_categories function. There are handful of categories in the system but this function just prints "NO Categories".

Can't figure out why.

Any ideas?


回答1:


  1. Make sure you have at least 1 Post in every category you want to display

  2. wp_list_categories should be outside of the wordpress LOOP. You'll probably need to provide the sidebar's code before the LOOP's code.




回答2:


You're using the right function, but you need to adjust a parameter for it. You are getting

No Categories

simply because the categories defined in the WordPress taxonomy have no posts assigned to them.

Try passing the hide_empty argument to wp_list_categories( $args ); 1 for true and 0 for false.

wp_list_categories('hide_empty=0');

This example will show all categories regardless of their post count.

Reference the wp_list_categories Codex page for more help.




回答3:


to use inside loop, use get_posts() instead of 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;


来源:https://stackoverflow.com/questions/2803248/wordpress-sidebar-issue-with-wp-list-categories-showing-no-categories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!