Typecho N天内评论最多的文章
时间:2020-08-01 阅读:436
Typecho N天内评论最多的文章
代码作用是N天内评论最多的N篇文章,这个N你可以自己定义,自己修改。
代码如下:
<?php function rmcp($days = 30,$num = 5){ $defaults = array( 'before' => '<ul>', 'after' => '</ul>', 'xformat' => '<li>{title}<span class="subcolor">已有评论数:{commentsNum}</span></li>' ); $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篇文章。
网友评论