宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

typecho的默认主题导航菜单部分调用的是独立页面,而我们搭建网站一般是把分类目录显示在导航栏,或者把分类目录和独立页面一起显示在导航栏,这样便于访客浏览网站目录。下面博客吧分享typecho分类目录显示在导航栏的代码。

只显示分类目录

在主题的header.php文件中找到代码:

<?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%20$pages->permalink);%20?>" title="<?php $pages->title); ?>"><?php $pages->title); ?></a>
<?php endwhile; ?>

 

修改为以下代码:

<?php $this->widget'Widget_Metas_Category_List')->to$category); ?>
<?php while$category->next)): ?>
<li><a<?php if$this->is'category', $category->slug)): ?> class="current"<?php endif; ?> href="<?php%20$category->permalink);%20?>" title="<?php $category->name); ?>"><?php $category->name); ?></a></li>
<?php endwhile; }?>

 

分类目录和独立页面都显示

在主题的header.php文件中找到代码:

<?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%20$pages->permalink);%20?>" title="<?php $pages->title); ?>"><?php $pages->title); ?></a>
<?php endwhile; ?>

 

在该代码上面添加代码:

<?php $this->widget'Widget_Metas_Category_List')->to$category); ?>
<?php while$category->next)): ?>
<li><a<?php if$this->is'category', $category->slug)): ?> class="current"<?php endif; ?> href="<?php%20$category->permalink);%20?>" title="<?php $category->name); ?>"><?php $category->name); ?></a></li>
<?php endwhile; }?>