typecho导航栏调用分类目录

时间:2020-08-01   阅读:685

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; }?>

文章由 博客吧 整理发布

上一篇:Typecho自定义文章评论列表样式

下一篇:非插件实现cookie版Typecho文章阅读次数统计功能

网友评论