Typecho模板的index页面

Typecho模板中的index页面,是模板的入口文件,也是唯一一个必须的文件。对于博客系统,index.php中,一般用于显示文章列表。本文将从index页面入手,逐步介绍整个模板的制作过程。

制作index.php
模板作者信息
在index.php的开头,可以使用注释方式添加模板作者信息。


那么在typecho后台,那么可以看到详细的作者信息。

引用页面片
直接使用$this->need()函数引用,譬如:

need('inc/header.php');?>
那么将会在index.php中插入inc/header.php的内容,相当于require。


public function need($fileName)
{
require $this->_themeDir . $fileName;
}
文章内容
先来个全景:

have()):?>
next()): ?>

title() ?>

发布于:date('y-m-d'); ?> 来自author(); ?>
category(','); ?>
content('阅读全文 >>'); ?>


暂无文章


pageNav('<< 上一页', '下一页 >>'); ?>

$this->have() 判断是否有文章输出
$this->next() 迭代到下一篇文章
$this->permalink() 输出文章的链接
$this->title() 输出文章标题
$this->category() 输出分类信息。参数表示分隔符。
$this->content() 输出文章内容
$this->excerpt(200) 输出文章摘要,参数200表示输出文章的前200字符
$this->author() 输出作者名称
$this->author->permalink() 输出作者的链接
如需要更加详细的字段说明,请参阅《Typecho模板中的Archive.php》

分页信息
使用$this->pageNav()输出标准的分页html。

pageNav的定义为:


public function pageNav($prev = '«', $next = '»', $splitPage = 3, $splitWord = '...', $template = '')
{
... ...
}
很多人怀疑,使用标准的分页输出,不利于个性化。但实际上,使用标准的html输出,对模板制作非常有利,减少学习成本,提高模板效率。

附上完整的例子参考:

$this->need('inc/header.php');
?>

have()):?>
next()): ?>

title() ?>

发布于:date('y-m-d'); ?> 来自author(); ?>
category(','); ?>
content('阅读全文 >>'); ?>


暂无文章


pageNav('<< 上一页', '下一页 >>'); ?>

$this->need('inc/footer.php');

发表新评论