在我们使用wordpress过程中,有时候会遇到这种情况:在添加菜单页面,分类目录默认不显示没有文章的分类。
有时一个新站在规划分类栏目时可能需要在侧边小工具中显示空的分类名称,可用一段代码解决此问题,将下的代码添加到当前主题functions.php中即可:
add_filter( 'widget_categories_args', 'wpb_force_empty_cats' ); function wpb_force_empty_cats($cat_args) { $cat_args['hide_empty'] = 0; return $cat_args; }
通过 wpb_force_empty_cats 改变默认 widget_categories_args 过滤器,将 hide_empty 设置为false,从而显示空的分类目录。