想要在博客每一篇博文结束的时侯加上几篇博客其他文章typecho 文章摘要,之后找到一个可以实现随机调阅起草人数文章的方式,代码来源 博客吧。实现方式很简单typecho 文章摘要,并且可以按照自己的需求订制。
打开方法
1、将下边的代码添加到主题的functions.php文件:
<pre class="has">`function getRandomPosts($limit = 10){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created limit($limit)
->order('RAND()')
);
if($result){
$i=1;
foreach($result as $val){
if($ipush($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
echo ''. '['.$post_title.'][2]</br>';
$i++;
}
}
pre>
2、在要显示随机文章的地方添加以下读取代码
<pre class="has">``</pre>
10 代表随机读取 10 篇文章,可以在须要的位置读取,例如博主就在主题目录下的 footer.php 文件中加入了如下代码:
<p><pre class="has">...
</br>
## 推荐阅读
</br>