Typecho模板中的post.php

post页面用于展示单片文章。由于post.php和archive.php都是由Widget_Archive加载,因此其api都是一样的。唯一不同的地方就是,archive.php页面中,Widget_Archive的栈中可能有多篇文章,而post页面中,则只有一篇。

这里也列出post中常用的一些api

  • $this->permalink() 输出文章的链接
  • $this->title() 输出文章标题
  • $this->category() 输出分类信息。参数表示分隔符。
  • $this->content() 输出文章内容
  • $this->expect(200) 输出文章摘要,参数200表示输出文章的前200字符
  • $this->author() 输出作者名称
  • $this->author->permalink() 输出作者的链接

另外,post页面相对于index或者archive页面,一般还会有“标签”和“评论”模块。

标签
tags(',', true, 'none'); ?>
获取当前单篇文章的标签,用“,”符号隔开。

评论

调用comments页面片:

<?php $this->need('comments.php'); ?>

其中,comments页面片内容可能如下:

<h4><?php $this->commentsNum(); ?></h4>
<ol>
    <?php $this->comments()->to($comments); ?>
        <?php while($comments->next()): ?>
    <li id="<?php $comments->theId(); ?>">
        <div class="comment_data">
                <?php echo $comments->sequence(); ?>.
                <strong><?php $comments->author(); ?></strong>
            </div>
        <div class="comment_body"><?php $comments->content(); ?></div>
    </li>
    <?php endwhile; ?>
</ol>
 

上一篇、下一篇

post页面中,往往加上上一篇、下一篇链接,可以极大方便用户阅读,并且有利于增加网站pv。其调用方法很简单,代码如下:

<php $this->thePrev('上一篇 : %s', '没有上一篇'); >
<php $this->theNext('下一篇 : %s', '没有下一篇'); >

或者

<php $this->thePrev('&laquo; %s', ''); >
<php $this->theNext('%s &raquo;', ''); >

输出文章的云标签

$this->widget('Widget_Metas_Tag_Cloud','ignoreZeroCount=1&limit=20')->to($tags);
$tags->parse('<a href="{permalink}">{name}</a>');