亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

WordPress 實現文章評論排行榜

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

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

使用方法是將以下各段代碼放置到需要顯示最熱日志的主題模板文件中適當的位置即可,如邊欄(sidebar.php)。

所有時間內評論最多日志


復制代碼
代碼如下:

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

這段代碼默認顯示前10篇評論最多的日志,數量10可修改為其它數值。
本周評論最多日志
要顯示本周評論最多日志,我們就可以使用如下的代碼,也就是在前面代碼的基礎上再添加一些額外的參數來實現:


復制代碼
代碼如下:

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


復制代碼
代碼如下:

<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”可以根據需要修改為其他值(如“1 year”, “7 days”, 等)。

本月評論最多日志
類似地,顯示當月評論最多的日志,可以使用下面的代碼:


復制代碼
代碼如下:

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

歡迎補充說明~

相關文章

最新評論