Typecho分类添加到导航菜单

将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'): ?>

过滤掉默认分类,其他过滤规则举一反三即可。

打赏
评论区
头像
文章目录
您是第 位访问本站的用户 👀

本站已运行:

萌ICP备20255521号