添加到当前主题的function.php
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 ‘'.$i.''.$post_title.'’;
$i++;
}
}
}
前台调用
“