Typecho 语法及函数集合
网友 目的地-Destination 整理的 Typecho 的语法及函数,挺全面的。保存下来,方便查阅!
模板函数
1、站点名称
<?php $this->options->title() ?>
2、站点网址
<?php $this->options ->siteUrl(); ?>
3、完整路径标题
<?php $this->archiveTitle(' » ', < span class="string">'', ' | '); ?>
//或
<?php $this ->options->title(); ?>
4、站点说明
<?php $this->options->description() ?>
5、模板文件夹地址
<?php $this->options->themeUrl(); ?>
6、导入模板文件夹内的 *.php 文件
<?php $this->need('*.php'); ?>
7、文章或者页面的作者
<?php $this->author(); ?>
8、作者头像
<?php $this->author->gravatar('40') ?>
//输出的是完整的标签,40是头像的宽和高。
9、文章作者全部文章列表链接
<?php $this->author->permalink (); ?>
10、文章作者个人主页链接
<?php $this->author->url(); ?>
11、文章作者的邮箱地址
<?php $this->author->mail(); ?>
12、上一篇与下一篇调用代码
<?php $this->thePrev(); ?>
<?php $this->theNext(); ?>
13、判断是否为首页,输出相关内容
<?php if ($this->is('index')): ?>
//首页输出内容
<?php else: ?>
//不是首页输出内容
<?php endif; ?>
14、文章或页面的评论数目
<?php $this->commentsNum('No Comments', '1 Comment' , '%d Comments'); ?>
15、截取部份文章(文章摘要)
<?php $this->excerpt(350, '...'); ?>
//首页每篇文章显示摘要),350 是字数
16、调用自定义字段
<?php $this->fields->fieldName; ?>
17、RSS 地址
<?php $this->options->feedUrl(); ?>
18、获取最新文章
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8&type=category')->parse('
'); ?>
19、文章分类名称(不带链接)
<?php $this->category(',', false); ?>
20、文章分类名称(带链接)
<?php if ($this->is('post')): ?>
<span>
<?php $this->category(' '); ?>
</span><?php endif; ?>
21、获取文章分类列表
-
widget('Widget_Metas_Category_List')->parse('
- {name} ({count}) '); ?>
22、获取某分类(mid=1)文章
-
widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
->parse('
- {title} '); ?>
23、获取最新评论列表
-
widget('Widget_Comments_Recent')->to($comments); ?>
next()): ?>
- author(false); ?>: excerpt(50, '...'); ?>
//数字50为截取评论的字数
24、获取最新文章(限制数量)
<?php while ($this->next()): ?>
<?php if ($this->sequence <= 3): ?>
//html代码,数字3为最近3篇文章
<?php endif; ?>
<?php endwhile; ?>
25、获取最新评论列表 (只显示访客评论不显示作者评论)
<? php $this->widget('Widget_Comments_Recent','ignoreAuthor=true')->to($comments); ?>
<? php while($comments->next()): ?>
<li>
<a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>:
<?php $comments->excerpt(50, '...'); ?>
</li>
<?php endwhile; ?>
26、获取文章时间归档
-
widget('Widget_Contents_Post_Date', 'type=month&format=F Y')->parse('
- {date} '); ?>
27、获取标签集合(标签云)
<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=28')->to($tags); ?>
<?php while($tags->next()): ?>
<a href="<?php $tags->permalink(); ?>" class="size-<?php $tags->split(5, 10, 15, 20); ?>"><?php $tags->name(); ?></a>
<?php endwhile; ?>
28、调用相关文章列表
<?php $this->related(5)->to($relatedPosts); ?>
<?php if ($relatedPosts->have()): ?> //这句也可以写成 if (count($relatedPosts->stack))
<ul>
<?php while ($relatedPosts->next()): ?>
<li>
<a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<li>无相关文章</li>
<?php endif; ?>
29、隐藏 head 区域的程序版本和模版名称
<?php $this->header("generator=&template="); ?>
34、获取当前文章页缩略图
<?php if ($this->attachment->isImage): ?>
<?php $this->attachments(1)->attachment->url(); ?>
<?php endif; ?>
//务必注意,这里所谓缩略图指的是当前文章页第一个附件地址,请确保第一个附件类型为图片。
35、根据页面类型显示内容
//判断是文章页则显示内容
<?php if ($this->is('post')): ?>
//想要显示的内容1
<?php endif; ?>
//判断是about页面页则显示内容
<?php if ($this->is('page', 'about')): ?>
//想要显示的内容2
<?php endif; ?>
36、Title增加副标题
<?php if ($this->is('index')): ?> - 副标题<?php endif; ?>
未完待续……