文档说明:
在之前的博文中我们已经阐述了利用Typecho标签功能进行文章二次归类的方法,二次归类的用途无外乎就是进行聚合推荐,所以今天我们主要讲如何根据文章Tag标签获取相关文章。
使用说明:
<?php $this->related(5)->to($relatedPosts); ?>
<ul>
<?php while ($relatedPosts->next()): ?>
<li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
<?php endwhile; ?>
</ul>
代码注释:
调用方式
$this->related($limits, $type);
参数说明
- $limits 默认值为 5,表示显示的相关文章数量
- $type 默认值为 NULL,表示文章的相关方式,只接受 author。当 $type 为 author
时,根据用户显示相关文章;为其他值时,根据标签显示相关文章。