制作index.php
模板作者信息
在index.php的开头,可以使用注释方式添加模板作者信息。
/**
* 这是一段描述,写在前面
* @package TypechoDev v2
* @author 地雷
* @version 2.0
* @link https://www.typechodev.com
*/
那么在typecho后台,那么可以看到详细的作者信息:
引用页面片
直接使用$this->need()函数引用,譬如:
<?php $this->need('inc/header.php');?>
那么将会在index.php中插入inc/header.php的内容,相当于require。
/**
* 获取主题文件
*
* @access public
* @param string $fileName 主题文件
* @return void
*/
public function need($fileName)
{
require $this->_themeDir . $fileName;
}
文章内容
先来个全景:
<?php if($this->have()):?>
<?php while($this->next()): ?>
发布于:<?php $this->date('y-m-d'); ?>
<?php $this->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的定义为:
/**
* 输出分页
*
* @access public
* @param string $prev 上一页文字
* @param string $next 下一页文字
* @param int $splitPage 分割范围
* @param string $splitWord 分割字符
* @param string $template 展现配置信息
* @return void
*/
public function pageNav($prev = '«', $next = '»', $splitPage = 3, $splitWord = '...', $template = '')
{
... ...
}
很多人怀疑,使用标准的分页输出,不利于个性化。但实际上,使用标准的html输出,对模板制作非常有利,减少学习成本,提高模板效率。
附上完整的例子参考:
/**
* 这是一段描述,写在前面
* @package TypechoDev v2
* @author 地雷
* @version 2.0
* @link https://www.typechodev.com
*/
$this->need('inc/header.php');
?>
<?php if($this->have()):?>
<?php while($this->next()): ?>
发布于:<?php $this->date('y-m-d'); ?>
<?php $this->pageNav('<< 上一页', '下一页 >>'); ?>
$this->need('inc/footer.php');
版权声明:未经书面授权禁止转载、摘编、复制或建立镜像。对既成事实本站将保留所有的权利。