Typecho常用的判断语法
最近在使用Maupassant主题的时候,偶然发现了一个小的样式Bug,主要就是页面头部导航在个别页面的展示效果会出错。因为调用的头部文件都是相同的,而样式却不同,所以问题基本是出现在页面判断。打开模版头部文件header.php第44行位置。
<a class="<?php if($this->is('index')): ?>current<?php endif; ?> <?php if($this->is('post')): ?>current<?php endif; ?>" href="<?php $this->options->siteUrl(); ?>"><?php _e('博客'); ?></a>
发现这段代码中,cho大佬只判断了首页、内容页;所以其他页面,包括标签、栏目、搜索页都会出现一些样式问题。只需要加上几个对应页面的判断语句就好了。
<a class="<?php if($this->is('index')): ?>current<?php endif; ?> <?php if($this->is('post')): ?>current<?php endif; ?> <?php if($this->is('tag')): ?>current<?php endif; ?> <?php if($this->is('category')): ?>current<?php endif; ?> <?php if($this->is('archive')): ?>current<?php endif; ?>" href="<?php $this->options->siteUrl(); ?>"><?php _e('博客'); ?></a>
Typecho可以使用is语法判断很多东西,比如
$this->is('index'); //判断首页
$this->is('archive'); //判断archive
$this->is('single'); //判断为阅读页面page+post
$this->is('page'); //判断独立页面page
$this->is('post'); //判断文章页面post
$this->is('category'); //判断分类页面
$this->is('tag'); //判断标签页面
$this->is('front'); //判断文章列表页面
$this->is('attachment'); //判断附件页面