By default the WordPress category widget does not show empty categories. Recently a new user asked us if it was possible to display empty categories in WordPress widget to help with his 地方发展. In this article, we will show you how to display empty categories in WordPress widgets.
默认情况下,WordPress类别小部件不显示空类别。 最近,一个新用户问我们是否可以在WordPress小部件中显示空类别,以帮助其进行地方发展 。 在本文中,我们将向您展示如何在WordPress小部件中显示空类别。

First thing you need to do is add this simple code snippet in your 儿童主题‘s 函数.php file or a 站点特定插件.
首先,您需要在副主题的函数.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;
}
This code hooks up our custom function wpb_force_empty_cats
to widget_categories_args
filter. Inside our function we have modified the option hide_empty
and set it to false.
此代码将我们的自定义函数wpb_force_empty_cats
到widget_categories_args
过滤器。 在函数内部,我们修改了选项hide_empty
并将其设置为false。
就这样,您现在可以将类别小部件拖放到 WordPress 网站上的任何侧边栏或小部件就绪区域。类别小部件现在也将显示空类别。
就是这样,您现在可以将类别小部件拖放到 WordPress 网站上的任何侧边栏或小部件就绪区域。类别小部件现在还将显示空类别。
If you’re working on a local development environment, then we recommend that you add some 虚拟内容 to your website for testing purposes.
如果您在本地开发环境中工作,则建议您将一些虚拟内容添加到您的网站中以进行测试。
Also don’t forget to check out our guide on how 类别和标签 work in WordPress.
另外,不要忘了查看我们有关WordPress中类别和标签如何工作的指南。
If you liked this article, then subscribe to our YouTube 频道 for more WordPress video tutorials. You can also find us on 推特 and 谷歌+.
如果您喜欢本文,请订阅我们的YouTube 频道,以获取更多WordPress视频教程。 您也可以在推特和谷歌+上找到我们。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-show-empty-categories-in-wordpress/