Typecho N天内评论最多的文章

No Reply , Posted in 代码 on January 15, 2015

代码作用是N天内评论最多的N篇文章,这个N你可以自己定义,自己修改。
代码如下:

<?php
function rmcp($days = 30,$num = 5){
    $defaults = array(
        'before' => '
    ', 'after' => '
', 'xformat' => '
  • {title}已有评论数:{commentsNum}
  • ' ); $time = time() - (24 * 60 * 60 * $days); $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('created >= ?', $time) ->where('type = ?', 'post') ->limit($num) ->order('commentsNum',Typecho_Db::SORT_DESC); $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}', '{commentsNum}'), array($val['permalink'], $val['title'], $val['commentsNum']), $defaults['xformat']); } echo $defaults['after']; } ?>

    调用代码:

    <?php rmcp(60,5);?>
    

    这个调用的意思是2个月内评论最多的前5篇文章。

    标签: 评论, 统计