When I was still using Typecho, I often tinkered with themes and plugins myself, and therefore frequently had to visit docs.typecho.org to look up commonly used functions for themes and plugins.
To make it easier for more developers and beginners to learn how to create Typecho themes more effectively and quickly, I organized some of the functions that are often used and am sharing them here for everyone to use!

Site Name
<?php $this->options->title() ?>
Site URL
<?php $this->options->siteUrl(); ?>
Full Path Title
<?php $this->archiveTitle(' » ', '', ' | '); ?><?php $this->options->title(); ?>
Site Description
<?php $this->options->description() ?>
Template Folder URL
<?php $this->options->themeUrl(); ?>
Import a PHP File from the Template Folder
<?php $this->need('.php'); ?>
Author of an Article or Page
<?php $this->author(); ?>
Author Avatar
<?php $this->author->gravatar('40') ?>
This outputs a complete img tag. 40 is the width and height of the avatar.
Link to All Articles by the Article's Author
<?php $this->author->permalink (); ?>
Link to the Article Author's Personal Homepage
<?php $this->author->url(); ?>
Email Address of the Article Author
<?php $this->author->mail(); ?>
Code for Calling the Previous and Next Articles
<?php $this->thePrev(); ?>
<?php $this->theNext(); ?>
Determine Whether This Is the Homepage and Output Related Content
<?php if ($this->is('index')): ?>
// 首页输出内容
<?php else: ?>
// 不是首页输出内容
<?php endif; ?>
Number of Comments on an Article or Page
<?php $this->commentsNum('No Comments', '1 Comment', '%d Comments'); ?>
Extract Part of an Article (Display an Excerpt for Each Article on the Homepage)
<?php $this->excerpt(200, '...'); ?>
200 is the number of characters to extract.
Call a Custom Field
<?php $this->fields->fieldName ?>
RSS URL
Get the Latest Posts
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8&type=category')->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
Plain-Text Category Names without Links
<?php $this->category(',', false); ?>
Get the Article Category List
<ul>
<?php
$this->widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
</ul>
Get Posts from a Specific Category
<ul>
<?php
$this->widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
</ul>
Get the Latest Comments List
<ul>
<?php $this->widget('Widget_Comments_Recent')->to($comments); ?>
<?php while($comments->next()): ?>
<li><a href="<?php $comments->permalink(); ?>">
<?php $comments->author(false); ?></a>:
<?php $comments->excerpt(50, '...'); ?></li>
<?php endwhile; ?>
</ul>
Limit the Number of Latest Articles Displayed on the Homepage
<?php while ($this->next()): ?>
<?php if ($this->sequence <= 3): ?>
html
<?php endif; ?>
<?php endwhile; ?>
Get the Latest Comments List, Version Two: Display Visitor Comments Only, Excluding the Blogger (That Is, the Author or Yourself)
<?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; ?>
Get the Article Date Archive
<ul>
<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')
->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
</ul>
Get the Tag Collection, Also Known as the Tag Cloud
<?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, 20, 30); ?>"><?php $tags->name(); ?></a>
<?php endwhile; ?>
Call the List of Related Articles for This Article
<?php $this->related(5)->to($relatedPosts); ?>
<?php if ($relatedPosts->have()): ?>
<?php while ($relatedPosts->next()): ?>
<li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<li>无相关文章</li>
<?php endif; ?>
Hide the Program Version and Template Name in the Head Section
<?php $this->header("generator=&template="); ?>
Get the Reader Wall
<?php
$period = time() - 999592000; // 时段: 30 天, 单位: 秒
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt','author', 'url', 'mail')
->from('table.comments')
->where('created > ?', $period )
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->where('authorId = ?', '0')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit(25)
);
$mostactive = '';
$avatar_path = 'http://www.gravatar.com/avatar/';
foreach ($counts as $count) {
$avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
$c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
$mostactive .= "<a href='" . $c_url . "' title='" . $count['author'] . " (参与" . $count['cnt'] . "次互动)' target='_blank'><img src='" . $avatar . "' alt='" . $count['author'] . "的头像' class='avatar' width='32' height='32' /></a>\n";
}
echo $mostactive;
?>
Display Different Content for Logged-In and Logged-Out Users
<?php if($this->user->hasLogin()): ?>
Visible to logged-in users
<?php else: ?>
Visible to both logged-out and logged-in users
<?php endif; ?>