Typecho 随机文章调用代码

August 14, 2016 • Read: 1616 • 杂的文



function theme_random_posts(){
$defaults = array(
'number' => 5,
'before' => '<ul class="list">',
'after' => '</ul>',
'xformat' => '<li><a href="{permalink}">{title}</a></li>'
$db = Typecho_Db::get();
 $sql = $db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
 $result = $db->fetchAll($sql);
echo $defaults['before'];
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($val);
echo str_replace(array('{permalink}', '{title}'),array($val['permalink'], $val['title']), $defaults['xformat']);
echo $defaults['after'];


<?php theme_random_posts();?>
Archives QR Code Tip
QR Code for this page
Tipping QR Code
Leave a Comment

已有 5 条评论
  1. I have noticed you don't monetize your website, don't waste your
    traffic, you can earn extra bucks every month because you've got hi quality content.
    If you want to know how to make extra money, search for: Boorfe's tips best
    adsense alternative

  2. Interesting article, keep updating your site

  3. Hello blogger, i must say you have hi quality articles here.
    Keep up good work.

  4. I have checked your website and i've found some duplicate content,
    that's why you don't rank high in google's search results,
    but there is a tool that can help you to create 100%
    unique content, search for: Boorfe's tips unlimited content

  5. 可以有