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