我正在显示带有此代码的菜单:
<!-- Subcategory menu from current category -->
<ul class="sub-menu">
<?php
if (is_home()) {
wp_list_categories('orderby=id&title_li=&depth=1');
}
else{
$category = get_the_category();
$cat_term_id = $category[0]->term_id;
$cat_category_parent = $category[0]->category_parent;
$listcat = wp_list_categories('echo=0&child_of='.$cat_category_parent.'&title_li=&orderby=order&order=ASC');
$listcat = str_replace("cat-item-".$cat_term_id, "cat-item-".$cat_term_id." current-cat", $listcat);
if ( in_category( $cat_term_id ) || post_is_in_descendant_category( $cat_term_id )) {
echo $listcat;
}
}
?>
并且该菜单的每个 li 使用以下方法显示帖子标题:
<!-- Post list from current category -->
<div class="menu_list">
<ul id="submenu_productos" class="clearfix">
<?php
$IDOutsideLoop = $post->ID;
while( have_posts() ) {
the_post();
foreach( ( get_the_category() ) as $category )
$my_query = new WP_Query('category_name=' . $category->category_nicename . '&orderby=date&order=DESC&showposts=100');
if( $my_query ) {
while ( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<!-- this line to hightlight current post in the category page -->
<li<?php if ( $post->ID == $wp_query->post->ID ) { echo ' class="test"'; } else {} ?>>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php
}
}
}
?>
</ul>
</div>
菜单运行良好,显示如下:
问题是,当我有一个属于该类别/子类别的帖子时,它也会显示在列表中......我想在它只有一个项目时隐藏它:
当子类别只有一个帖子时,有什么办法可以隐藏它?
PD:请不要告诉我把它放在 wordpress.stackexchange.com 上,我总是在那里发帖,没有答案,这里的人总是帮助我......