将Typecho分类添加到导航菜单,需要排除默认分类
默认分类
Typecho初级
Typecho中级
Typecho高级
实现方法
编辑主题下的header.php
文件,将分类代码添加到header.php
模板文件中“首页
”导航位置的后面即可,代码如下:
<?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
<?php while ($category->next()): ?>
<?php if ($category->slug!=='default'): ?>
<a<?php if ($this->is('post')): ?>
<?php if ($this->category == $category->slug): ?> class="current"<?php endif; ?>
<?php else: ?>
<?php if ($this->is('category', $category->slug)): ?> class="current"<?php endif; ?>
<?php endif; ?> href="<?php $category->permalink(); ?>"><?php $category->name(); ?></a>
<?php endif; ?>
<?php endwhile; ?>
说明
其中第三行是根据默认分类的slug
值
<?php if ($category->slug!=='default'): ?>
过滤掉默认分类,其他过滤规则举一反三即可。