Typecho设置父分类和子分类不同样式的方法
为Typecho的子分类设置二级菜单
就是普通的分类,正常输出;有子分类的父级分类,输出后点击它会展开二级菜单里面有这个父级旗下的子分类。类似下面的两个GIF图片效果。
! 2999077510.gif 1
! 3212954768.gif 2<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?>
<?php while($categorys->next()): ?>
<?php if ($categorys->levels === 0): ?>
<?php $children = $categorys->getAllChildren($categorys->mid); ?>
<?php if (empty($children)) { ?>
<li <?php if($this->is('category', $categorys->slug)): ?> class="active"<?php endif; ?>>
<a href="<?php $categorys->permalink(); ?>" title="<?php $categorys->name(); ?>"><?php $categorys->name(); ?>
<span class="badge"><?php $categorys->count(); ?></span></a>
</li>
<?php } else { ?>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" data-target="#"><?php $categorys->name(); ?> <b class="caret"></b></a>
<ul class="dropdown-menu">
<?php foreach ($children as $mid) { ?>
<?php $child = $categorys->getCategory($mid); ?>
<li <?php if($this->is('category', $mid)): ?> class="active"<?php endif; ?>>
<a href="<?php echo $child 'permalink' ?>" title="<?php echo $child 'name' ; ?>"><?php echo $child 'name' ; ?>
<span class="badge" style="float:right;"><?php echo $child 'count' ; ?></span></a>
</li>
<?php } ?>
</ul></li>
<?php } ?><?php endif; ?><?php endwhile; ?>
1 : https://magicblue.cn/usr/uploads/2023/09/1283361314.gif
2 : https://magicblue.cn/usr/uploads/2023/09/282444077.gif