WordPress 實(shí)現(xiàn)文章評(píng)論排行榜
用到了WordPress功能函數(shù)Query_post()的一種高級(jí)用法,就是獲取本周或當(dāng)月或最近30天評(píng)論最多的一定數(shù)量的日志。
使用方法是將以下各段代碼放置到需要顯示最熱日志的主題模板文件中適當(dāng)?shù)奈恢眉纯?,如邊欄(sidebar.php)。
所有時(shí)間內(nèi)評(píng)論最多日志
<ul> <?php query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC'); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
這段代碼默認(rèn)顯示前10篇評(píng)論最多的日志,數(shù)量10可修改為其它數(shù)值。
本周評(píng)論最多日志
要顯示本周評(píng)論最多日志,我們就可以使用如下的代碼,也就是在前面代碼的基礎(chǔ)上再添加一些額外的參數(shù)來(lái)實(shí)現(xiàn):
<ul> <?php $week = date('W'); $year = date('Y'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC&year=' . $year . '&w=' . $week); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
最近30天評(píng)論最多日志
<ul> <?php function filter_where($where = '') { //posts in the last 30 days $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC'); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
“30 days”可以根據(jù)需要修改為其他值(如“1 year”, “7 days”, 等)。
本月評(píng)論最多日志
類似地,顯示當(dāng)月評(píng)論最多的日志,可以使用下面的代碼:
<ul> <?php $month = date('m'); $year = date('Y'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC&year=' . $year . '&monthnum=' . $month); while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
歡迎補(bǔ)充說(shuō)明~
上一篇:七牛鏡像存儲(chǔ) WordPress 插件(一鍵實(shí)現(xiàn) WordPress 博客靜態(tài)文件 CDN加速)
欄 目:WordPress
下一篇:WordPress配置文件wp-config.php詳解
本文標(biāo)題:WordPress 實(shí)現(xiàn)文章評(píng)論排行榜
本文地址:http://mengdiqiu.com.cn/a1/WordPress/12748.html
您可能感興趣的文章
- 05-31wordpress修改后臺(tái)登錄地址教程
- 05-31WordPress自定義用戶頭像實(shí)現(xiàn)代碼
- 01-11修改wordpress上傳臨時(shí)目錄解決wordpress無(wú)法安裝插件包的方法
- 01-11WordPress增加文章排序方式
- 01-11自己做wordpress評(píng)論插件修改評(píng)論樣式(兩步美化評(píng)論內(nèi)容)
- 01-11wordpress get
- 01-11wordpress獲取文章評(píng)論數(shù)過(guò)濾掉作者代碼分享
- 01-11在wordpress文章末尾添加內(nèi)容的簡(jiǎn)單方法
- 01-11不用wordpress插件顯示文章瀏覽統(tǒng)計(jì)功能代碼修改(原理分析)
- 01-11wordpress dynamic


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 05-31wordpress修改后臺(tái)登錄地址教程
- 05-31WordPress自定義用戶頭像實(shí)現(xiàn)代碼
- 01-11WordPress增加文章排序方式
- 01-11修改wordpress上傳臨時(shí)目錄解決wordpre
- 01-11wordpress get
- 01-11自己做wordpress評(píng)論插件修改評(píng)論樣式
- 01-11在wordpress文章末尾添加內(nèi)容的簡(jiǎn)單方
- 01-11wordpress獲取文章評(píng)論數(shù)過(guò)濾掉作者代
- 01-11wordpress dynamic
- 01-11不用wordpress插件顯示文章瀏覽統(tǒng)計(jì)功
隨機(jī)閱讀
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置