最近在折腾Typecho主题,博主也不太懂PHP,所以只好收集一堆Typecho的调用函数,这里记录一下,以便日后翻查,当然,如果能帮助到别人就更好了。
想看看博主的最新研究成果?这里:32mb.cn
话说Typecho的函数类似于js的调用方法,玩过js的人一看就明白。
这篇文章会一直更新,持续到博主不再折腾Typecho。

下面是相关的函数。

1、站点名称

  • <?php $this->options->title() ?>
复制

2、站点网址

  • <?php $this->options ->siteUrl(); ?>
复制

3、完整路径标题如分享几个Typecho中常用的调用函数| 苹果树下

  • <?php $this->archiveTitle(‘ &raquo; ‘, < span class=”string”>’’, ‘ | ‘); ?><?php $this ->options->title(); ?>
复制

4、站点说明

  • <?php $this->options->description() ?>
复制

5、模板文件夹地址

  • <?php $this->options->themeUrl(); ?>
复制

6、导入模板文件夹内的php文件

  • <?php $this< /span>->need('.php'); ?>
复制

7、文章或者页面的作者

  • <?php $this->author(); ?>
复制

8、作者头像

  • < ?php $this->author->gravatar('40') ?>
复制

此处输出的完整的img标签,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: ?>
  • //不是首页输出内容
  • < span><?php endif; ?>
复制

14、文章或页面,评论数目

  • <?php $this->commentsNum('No Comments', '1 Comment' , '%d Comments'); ?>
复制

15、截取部份文章(首页每篇文章显示摘要),350是字数

  • <?php $this->excerpt(350, ‘.. .’); ?>
复制

16、增强版文章截取

  • <?php
  • preg_match_all('/<p>.*?<\/p>/im', $this->content, $m);
  • if(count($m[0])>0){
  • if(strlen($m[0][0])<200){
  • $result = $m[0][0].$m[0][1];
  • } else {
  • $result = $m[0][0];
  • }
  • $result = preg_replace("/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/","",$result); #注释这一行可让摘要中带图片
  • echo $result;
  • } else{
  • $this->excerpt(300, '...');
  • }
  • ?>
复制

17、调用自定义字段(官方文档坑爹,竟然没有,博主自己摸索出来的)

  • <?php $this->fields->fieldName ?>
复制

18、手气不错:随机浏览文章
参考:https://kkp.disk.st/redirect-to-random-post.html