在当前主题的functions.php文件中添加以下函数代码:

function getHotComments($limit = 10){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post') //添加这一句避免未达到时间的文章提前曝光
->limit($limit)
->order('commentsNum', Typecho_Db::SORT_DESC)
);
if($result){
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_blank">'.$post_title.'</a></li>';
}
}
}

在要调用热评文章位置对应的模板文件(如index.php、single.php、sidebar.php或page.php等)添加调用代码:

<?php getHotComments('10');?>

最新文章

  1. Nancy FormsAuthentication使用
  2. Codeforces Round #383 (Div. 2) 题解【ABCDE】
  3. 使用 margin 让div块内容居中
  4. DreamFactory service platform 将DB发布成restful service
  5. 查看Linux版本系统信息方法汇总
  6. c# 远程监控(4) 接收端 RTP包重组 分屏显示
  7. 自己定义actionbar
  8. PAT 1057
  9. 升级 mysql5.6 配置文件my.cnf sql_mode 解析与设置问题
  10. git在多迭代版本的应用
  11. [sublime] 利用sublime搭建C/C++编译器
  12. Python3练习题 001:4个数字求不重复的3位数
  13. FindExecutable:查找与一个指定文件关联在一起的程序的文件名
  14. 【转】使用Mybatis时遇到的延迟加载造成返回异常的问题——HttpMessageConversionException: Type definition error
  15. 多分类-- ROC曲线
  16. swift - 使用系统app导航
  17. Spark笔记之使用UDF(User Define Function)
  18. 学习Css补充知识点
  19. 长沙雅礼中学集训-------------------day3
  20. 设计模式学习——代理模式(Proxy Pattern)

热门文章

  1. php的ob缓存详解
  2. MyBatis代理开发(2)
  3. golang语言中sync/atomic包的学习与使用
  4. vue.js路由vue-router
  5. css布局之头尾固定中间高度自适应
  6. Linux apt-get命令
  7. HTTP.ResponseCode
  8. sql重复数据的过滤问题
  9. Can&#39;t find bundle for base name test.properties, locale zh_CN
  10. 10分钟搭建 App 主流框架