# 功能函数代码
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(); ?>