什么都不说,先看代码:

    <nav class="collapse g7-sidenav" id="g7-cat-nav">    
        <?php
        $this->widget('Widget_Metas_Category_List')->to($categories);
        if($categories->have()){
            while($categories->next()){?>
            <div class="g7-sidenav-item <?php if($categories->parent == 0 ): ?>cat-parent<?php else: ?>cat-child<?php endif;?> <?php if($this->category == $categories->slug): ?> active<?php endif; ?>" id="<?php $categories->slug(); ?>">
                <a class="g7-sidenav-link d-flex" href="<?php $categories->permalink(); ?>">
                <?php if($this->category == $categories->slug): ?>
                <svg class="px-1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
                <?php else: ?>
                <svg  class="px-1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg>
                <?php endif; ?><?php $categories->name(); ?></a>
                <?php
                if ($categories->count == 0) { $pagesize = 0;} else{ $pagesize = 25;};
                $this->widget('Widget_Archive@'.$categories->name, 'pageSize='.$pagesize.'&type=category', 'mid='.$categories->mid)->to($categoryposts);
                    if($categoryposts->have()){ ?>
                        <ul class="nav g7-sidenav-list">
                        <?php while ($categoryposts->next()) { ?>
                        <li <?php if($this->slug == $categoryposts->slug): ?> class="active g7-sidenav-list-active"<?php endif; ?>><a href="<?php $categoryposts->permalink(); ?>"><?php $categoryposts->title(); ?></a></li>
                        <?php
                        }
                        echo '</ul>';
                    }
                        echo '</div>';
            }
        }else{
            echo '无分类';
        }
        ?>
    </nav>

最主要的是14行的代码,通过$categories->count判断目录下是否有直接文章,没有就不显示,有的话就显示25个,不然文章多了就受不了了

2017.11.24更新

通过一个while(){}和while(): endwhile的原因,发现自己写的这段代码真特么的乱,自己想修改都看的累死,所以,改了。

<nav class="collapse g7-sidenav" id="g7-cat-nav">    
    <?php  $this->widget('Widget_Metas_Category_List')->to($categories); ?>
    <?php if($categories->have()): ?>
        <?php while($categories->next()):?>
            <div class="g7-sidenav-item <?php if($categories->parent == 0 ): ?>cat-parent<?php else: ?>cat-child<?php endif;?> <?php if($this->category == $categories->slug): ?> active<?php endif; ?>" id="<?php $categories->slug(); ?>">
                <a class="g7-sidenav-link d-flex" href="<?php $categories->permalink(); ?>">
                <?php if($this->category == $categories->slug): ?>
                    <svg class="px-1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
                <?php else: ?>
                    <svg  class="px-1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg>
                <?php endif; ?>
                <?php $categories->name(); ?>
                </a>
            <?php if ($categories->count == 0) : $pagesize = 0; else: $pagesize = 25; endif; ?>
            <?php $this->widget('Widget_Archive@'.$categories->name, 'pageSize='.$pagesize.'&type=category', 'mid='.$categories->mid)->to($categoryposts); ?>
                <?php if($categoryposts->have()) : ?>
                    <ul class="nav g7-sidenav-list">
                        <?php while ($categoryposts->next()) : ?>
                        <li <?php if($this->slug == $categoryposts->slug): ?> class="active g7-sidenav-list-active"<?php endif; ?>><a href="<?php $categoryposts->permalink(); ?>"><?php $categoryposts->title(); ?></a></li>
                        <?php endwhile; ?>
                    </ul>
                <?php endif; ?>
            </div>
        <?php endwhile; ?>
    <?php else : ?>
        <?php _e('无分类'); ?>
    <?php endif; ?>
</nav>