zoukankan      html  css  js  c++  java
  • typecho 调用评论最多热门文章

    在当前主题的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');?>
  • 相关阅读:
    Python
    Python
    Python
    Python
    python
    python
    Python
    pure css做的pc登陆界面
    MvcAdmin功能介绍
    pure css做的手机版博客园(我自己博客)
  • 原文地址:https://www.cnblogs.com/fan-bk/p/8417593.html
Copyright © 2011-2022 走看看