# 功能函数代码
function getRandomPosts(){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post')
->where('password is NULL')
->limit(1)
->order('RAND()')
);
if($result){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($result[0]);
return $val['permalink'];
}
}
# 调用代码
<?php echo getRandomPosts(); ?>
本文介绍了一个名为getRandomPosts的函数,它从Typecho数据库中查询并返回最新、已发布且未设置密码的随机文章的permalink。





