王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

Typecho热评文章的挪用要领教程

热评文章即网站中被批评次数最多的文章,平常热评文章、热点文章和随机文章是网站经常使用的排行文章模块,那末typecho网站要如安在页面中显现批评最多的文章列表?很简单,代码博客吧已准备好,有须要的博主仅须要依据下面的申明增加即可。

操纵步骤:

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

123456789101112131415161718

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、在要挪用热评文章位置对应的模板文件(如index.php、single.php、sidebar.php或page.php等)增加挪用代码:

1

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

代码中的10示意要挪用的文章数目。

文章由 博客吧 整顿宣布

相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。