最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WordPress 實(shí)現(xiàn)文章評(píng)論排行榜

  發(fā)布時(shí)間:2014-07-20 11:39:40   作者:佚名   我要評(píng)論
本文主要用到了WordPress功能函數(shù)Query_post()的一種高級(jí)用法,就是獲取本周或當(dāng)月或最近30天評(píng)論最多的一定數(shù)量的日志,需要的朋友可以參考下

用到了WordPress功能函數(shù)Query_post()的一種高級(jí)用法,就是獲取本周或當(dāng)月或最近30天評(píng)論最多的一定數(shù)量的日志。

使用方法是將以下各段代碼放置到需要顯示最熱日志的主題模板文件中適當(dāng)?shù)奈恢眉纯?,如邊欄(sidebar.php)。

所有時(shí)間內(nèi)評(píng)論最多日志


復(fù)制代碼
代碼如下:

<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):


復(fù)制代碼
代碼如下:

<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)論最多日志


復(fù)制代碼
代碼如下:

<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)論最多的日志,可以使用下面的代碼:


復(fù)制代碼
代碼如下:

<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ō)明~

相關(guān)文章

最新評(píng)論

尚志市| 葫芦岛市| 织金县| 马边| 始兴县| 丰城市| 和田市| 车致| 大连市| 淮南市| 府谷县| 治多县| 定边县| 尼木县| 天水市| 商南县| 广西| 新化县| 利辛县| 孟连| 上林县| 白山市| 武强县| 溆浦县| 沂南县| 曲水县| 安泽县| 墨玉县| 东辽县| 夏邑县| 五家渠市| 兰坪| 板桥市| 华安县| 武鸣县| 安图县| 定兴县| 盐城市| 东兴市| 桦南县| 民县|