Typecho标题导航栏的输出格式,父分类和子分类
就是普通的分类,正常输出;有子分类的父级分类,输出后点击它会展开二级菜单里面有这个父级旗下的子分类。
普通的输出分类格式代码为:
<?php
$this->widget('Widget_Metas_Category_List')->to($cats);
$i=0; $b_arr = fa_ico();
?>
<?php while ($cats->next()): ?>
<li><a href="<?php $cats->permalink()?>"><?php echo $b_arr[$i]; ?> <?php $cats->name()?></a></li>
<?php $i++; ?>
<?php endwhile; ?>
输出一级分类和二级分类:
<?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)): ?> <?php endif; ?>>
<a href="<?php $categorys->permalink(); ?>" title="<?php $categorys->name(); ?>" target="_blank">
<?php $categorys->name(); ?></a>
</li>
<?php } else { ?>
<li>
<a><i class="fa fa-file-text-o"></i><?php $categorys->name(); ?></a>
<!-- 二级标题 -->
<ul class="sub-menu">
<?php foreach ($children as $mid) { ?>
<?php $child = $categorys->getCategory($mid); ?>
<li <?php if($this->is('category', $mid)): ?> class="current-menu-item"<?php endif; ?>>
<a href="<?php echo $child['permalink'] ?>" title="<?php echo $child['name']; ?>"><?php echo $child['name']; ?></a>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php endif; ?>
<?php endwhile; ?>