0, Preface
When I first came into contact with Typecho, I saw a lot of words like $this->
, but I didn’t know what it meant. I checked the documentation and found out that it is a special syntax, and some parameters of the current page can be called.
1, syntax list
Site name
1 | <?php $this->options->title() ?> |
site url
1 | <?php $this->options->siteUrl(); ?> |
site introduction
1 | <?php $this->options->description() ?> |
Author of the article/page
1 | <?php $this->author(); ?> |
Author Avatar
1 | <?php $this->author->gravatar('40') ?> |
Among them, 40
is the avatar size, which can be modified.
call up and down
1 | <?php $this->thePrev(); ?> <?php $this->theNext(); ?> |
Determine whether it is the home page and output relevant content
1 | <?php if ($this->is('index')): ?> // is the output content of the home page <?php else: ?> //not the home page output content <?php endif; ?> |
Number of Article/Page Comments
1 | <?php $this->commentsNum('No Comments', '1 Comment' , '%d Comments'); ?> |
Intercept the content of the article and display the summary
1 | <?php $this->excerpt(350, '.. .'); ?> |
Among them, 350
is the number of words to intercept the summary.
call custom fields
1 | <?php $this->fields->fieldName ?> |
filedName
is the field name, for example the language
field can be written:
1 | <?php $this->fields->language ?> |
RSS address
1 | <?php $this->options->feedUrl(); ?> |
Get the latest review list
1 | <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> |
Category Name
1 | <?php $this->category(',', false); ?> |
Get article time archive
1 | <ul> <?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y') ->parse('<li><a href="{permalink}">{date}</a></li>'); ?> </ul> |
Get the label collection
1 | <?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; ?> |
Display different content for logged-in and non-logged-in users
1 | <?php if($this->user->hasLogin()): ?> // login visible <?php else: ?> // Both logged in and logged in are visible <?php endif; ?> |
Typecho $this Syntax
Comments