Typecho相关文章
AI摘要:文章介绍了Typecho博客系统中相关文章功能的实现代码,通过PHP代码判断并显示最多5篇相关文章。作者计划后续添加无相关文章时随机显示文章的功能。
增加了一个判断有没有相关文章:
<?php $this->related(5)->to($relatedPosts); ?>
<?php if ($relatedPosts->next()): ?>
<ul class="related-posts">
<?php while ($relatedPosts->next()): ?>
<li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
后期应该再加上如果没有相关文章,随机显示一些文章。