Typecho call Popular Articles

Lively article that is to be the site most commented articles, general Lively articles, popular articles and random articles are commonly used website ranking article module, then typecho site to show how most commented list of articles in the page? Very simple, the code is ready, there is a need to bloggers only need to add the following description.

1. Add the following function codes in the functions.php file in the current topic:

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>'; } } }

2, in a position to invoke Article Lively corresponding template file (such as index.php, single.php, sidebar.php or page.php, etc.) to add calling code:

<?php getHotComments('10');?>
Among them, 10 represents the number of calls

Guess you like

Origin www.cnblogs.com/fdfgfggh/p/12014309.html