php get_categories() 只返回使用中的类别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11154928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get_categories() only returns categories in use
提问by John
$args = array(
"type" => "post",
"orderby" => "name",
"order" => "ASC");
$types = get_categories($args);
When this is executed. $types only contains "Uncategorized" since it is used as the default to my posts. There are other categories available, but they are not returned unless I have a post that uses them. How can I return all possible categories and not just the ones that are in use?
执行此操作时。$types 只包含“未分类”,因为它被用作我帖子的默认值。还有其他类别可用,但除非我有使用它们的帖子,否则不会返回它们。如何返回所有可能的类别,而不仅仅是正在使用的类别?
回答by coolguy
<?php $args = array("hide_empty" => 0,
"type" => "post",
"orderby" => "name",
"order" => "ASC" );
$types = get_categories($args);
?>
回答by Grávuj Miklós Henrich
For this I suggest to use:
为此,我建议使用:
wp_list_categories( $args );
Further explanations about this function and how to use: http://codex.wordpress.org/Template_Tags/wp_list_categories
关于此功能以及如何使用的进一步说明:http: //codex.wordpress.org/Template_Tags/wp_list_categories

