Typecho调用热门评论文章

由 Jefsky 发布于 2024-01-04

在当前主题function.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>`';
    }
}
}

前台调用

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