当我使用get_categories()
在存档中。php文件,已激活hide\\u empty(true | 1),然后向该文件发送年份值。hide\\u empty参数失去了作用。无论如何,所选年份中没有帖子的类别都会显示出来。
如果没有从所选年份连接的帖子,如何隐藏类别?
Edit: 我的代码:
<?php
if (!empty($_GET[\'m\']))
{
?>
<h2><?php echo _e(\'Categories\'); ?></h2>
<ul>
<?php
foreach(get_categories(\'parent=0&hide_empty=1\') as $category)
{
$my_query = new WP_Query(\'cat=\'.$category->term_id.\'&year=\'.$_GET[\'m\'].\'&posts_per_page=-1\');
$count = $my_query->post_count;
?>
<li><a class="name" href="?cat=<?=$category->term_id?>&year=<?=$_GET[\'m\']?>"><?=$category->name?> (<?=$count?>)</a></li>
<?php
$cats = get_categories(\'parent=\'.$category->term_id.\'&year=\'.$_GET[\'m\'].\'&hide_empty=1\');
if (count($cats))
{
?>
<ul>
<?php
foreach($cats as $category)
{
$my_query = new WP_Query(\'cat=\'.$category->term_id.\'&year=\'.$_GET[\'m\'].\'&posts_per_page=-1\');
$count = $my_query->post_count;
?>
<li><a class="name" href="?cat=<?=$category->term_id?>&year=<?=$_GET[\'m\']?>"><?=$category->name?> (<?=$count?>)</a></li>
<?php
}
?>
</ul>
<?php
}
}
?>
</ul>
<?php
}
?>