面面包屑导航可以显示发布日期、类别或标签,它们表示当前页面在导航层次结构内的位置,可以帮助博主清晰思路;减少返回到上一级页面的操作,能帮读者更好的找到自己需要的文章内容,提高了用户体验,是SEO工作必须要考虑和操作的部分。下面我们来尝试通过代码来实现Typecho的面包屑导航。
具体代码如下:
<div class="breadcrumb">
<?php if($this->is('index')):?><!-- 页面首页时 -->
<a href="<?php $this->options->siteUrl(); ?>" title="<?php $this->options->title(); ?>">首页</a> >
<?php elseif ($this->is('post')): ?><!-- 页面为文章单页时 -->
<a href="<?php $this->options->siteUrl(); ?>" title="<?php $this->options->title(); ?>">首页</a> > <?php $this->category(); ?> > <?php $this->title(); ?>
<?php else: ?><!-- 页面为其他页时 -->
<a href="<?php $this->options->siteUrl(); ?>" title="<?php $this->options->title(); ?>">首页</a> > <?php $this->archiveTitle(' » ','',''); ?>
<?php endif; ?>
</div>
完成代码撰写后,我们把他们添加到需要显示面包屑位置对应的模板文件中即可,如header.php。