Typecho 模板开发常用 api

模板头部相关信息输出

$this->keywords('_');                  //关键词
$this->options->title();               //站点名称
$this->options->description();         //站点描述
$this->options->themeUrl('ie.css');    //通过模板路径拼接资源url
$this->options->siteUrl();             //主页网址
$this->options->feedUrl();
$this->options->commentsFeedUrl();
$this->options->generator();           //版本号
$this->pageNav();                      //分页
$this->archiveTitle();                 //标题

is函数

之前有详细讲解过,客官请移步这里查阅

归档页面相关函数

  $this->title()               //当前row的标题
  $this->permalink()           //当前row的链接
  $this->author()              //当前row的作者
  $this->autor->permalink()    //当前row的作者的链接
  $this->date()                //当前row的发布日期,参数可以指定format
  $this->category()            //当前row的分类名称
  $this->tags(', ', true, ''); //标签
  $this->commentsNum()         //当前row的评论个数
  $this->content()             //当前row的文章内容
  $this->excerpt()             //当前row的摘要输出,可以通过参数指定max-length
  $this->thePrev('« %s', '');    //上一篇
  $this->theNext('%s »', '');    //下一篇
  $this->related(5)->to($relatedPosts) //相关文章调用,当然也可以直接使用Widget方式调用

归档页面,通指index、post、archive等页面,也就是说,在文章、归档或者首页,均可以使用上述函数。具体源码分析,请参考《Typecho中Widget_Archive解析》一文。

评论内容

获取comments实例对象的多种方式

$this→comments()->to($comments);               //显示全部(默认)
$this→comments('comment')→to($comments);       //只显示 comment
$this→comments('trackback')→to($trackbacks);   //只显示 trackback
$this→comments('pingback')→to($pingbacks);     //只显示 pingback

通过comments对象获取相关信息

$comments->author(true);         //输出评论人昵称,参数true为带链接的,false为不带链接的.ps.其实还有一个参数,类型也是布尔,作用是是否带noFollow
$comments->excerpt(18, '...');   //输出评论摘要,第一个参数是要截取的长度,第二个是截取后的字符串;
$comments->permalink();          //获取当前评论链接,木有参数;
$comments->title();              //获取当前评论标题,同样木有参数;
$comments->dateWord();           //输出词义化日期,就是输出“3小时前”、“三天前”之内的;
$comments->gravatar();           //调用gravatar输出用户头像,有两个参数,第一个是头像尺寸,默认是32,第二个是默认输出的头像。

其他

如需学习Typecho主题模板制作,可以参考官方的文档《模板制作快速入门》