typecho导航栏调用分类目录
网站文章 2026-09-21 06:44:05 3 0

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

只显示分类目录

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

1
2
3
4
<?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; ?>

修改为以下代码:

1
2
3
4
<?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 $category->permalink(); ?>" title="<?php $category->name(); ?>"><?php $category->name(); ?></a></li>
<?php endwhile; }?>

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

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

1
2
3
4
<?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; ?>

在该代码上面添加代码:

1
2
3
4
<?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 $category->permalink(); ?>" title="<?php $category->name(); ?>"><?php $category->name(); ?></a></li>
<?php endwhile; ?>
文章说明
本文标签:
©版权声明
本站提供的一切软件、教程和游戏辅助仅限用于娱乐和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集,版权争议与本站无关。如有侵权请邮件与我们联系处理。敬请谅解!6594404@qq.com