select('COUNT(*) AS count') ->from('table.contents') ->where('status = ?', 'publish') ->where('type = ?', 'post') ->where('created <= ?', time()); $countResult = $db->fetchRow($countSql); $total = $countResult['count']; if ($total > 0) { // 随机选择一个偏移量 $offset = mt_rand(0, $total - 1); // 根据偏移量获取一篇文章 $sql = $db->select() ->from('table.contents') ->where('status = ?', 'publish') ->where('type = ?', 'post') ->where('created <= ?', time()) ->limit(1) ->offset($offset); $result = $db->fetchRow($sql); if (!empty($result)) { $target = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($result); return $target['permalink']; } } return false; } // 获取随机文章链接 $randomPostUrl = getRandomPost(); $this->need('header.php'); ?>
options->showsidebar): ?>

随机阅读

正在为您随机选择一篇文章...

请稍候,正在跳转中...

Loading...
options->showsidebar): ?> need('sidebar.php'); ?>
need('footer.php'); ?>