Typecho默认主题下添加分类导航菜单
Typecho真的是很简洁呢!
不过我就喜欢折腾!
这不,刚买上阿里云主机并且备案,就开始折腾了!
附上我的推荐码[mzc9if]
说说怎么添加分类导航菜单吧。
在默认主题的header.php
文件中找到导航菜单代码:
<nav id="nav-menu" class="clearfix" role="navigation">
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php while($pages->next()): ?>
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
<?php endwhile; ?> </nav>
可以发现,除了首页外,后面的就是页面的导航菜单输出了。
那我们直接复制一份改下不就好了,改动如下:
<nav id="nav-menu" class="clearfix" role="navigation">
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?><!--页面输出-->
<?php while($pages->next()): ?>
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
<?php endwhile; ?>
<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?><!--分类输出-->
<?php while($categorys->next()): ?>
<a<?php if($this->is('category', $categorys->slug)): ?> class="current"<?php endif; ?> href="<?php $categorys->permalink(); ?>" title="<?php $categorys->title(); ?>"><?php $categorys->title(); ?></a>
<?php endwhile; ?>
</nav>
成功了有木有!
不过咋导航菜单没有显示分类名称呢?- -奇葩
我去Typecho官方文档查了下,找到如下代码:
<?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a> ({count})</li>'); ?>
发现分类名称用的是name
,于是改成如下代码:
<nav id="nav-menu" class="clearfix" role="navigation">
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?><!--页面输出-->
<?php while($pages->next()): ?>
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
<?php endwhile; ?>
<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?><!--分类输出-->
<?php while($categorys->next()): ?>
<a<?php if($this->is('category', $categorys->slug)): ?> class="current"<?php endif; ?> href="<?php $categorys->permalink(); ?>" title="<?php $categorys->name(); ?>"><?php $categorys->name(); ?></a>
<?php endwhile; ?>
</nav>
OK!而且还有选中效果!
就这样啦!
以后还有的折腾!

折腾了我一天时间,用兄台你的方法成功了,实在感谢!