Typecho 判断当前处于什么页面 - 神奇的 is 语法

粗略判断

$this->is('index'); // 是主页
$this->is('archive'); // 是存档页面,包括分类页面、标签页面、日期归档页面等
$this->is('single'); // 是内容页面,例如文章详情页、独立页面、附件详情页
$this->is('page'); // 是独立页面
$this->is('post'); // 是文章详情页
$this->is('category'); // 是分类页面
$this->is('tag'); // 是标签页面
$this->is('attachment'); // 是附件页面

精确判断

$this->is('category', 'default'); // 第二个参数是分类的 slug
$this->is('page', 'start'); // 是独立页面中的 start 页面
$this->is('post', 1); // 是否是 cid 等于 1 的文章的详情页

常见用法

<?php
    if($this->is('index')){
        // do something
    }else{
        // do something
    }
?>