WordPress 完成文章评论排行榜

用到了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>

欢送补充阐明~

以上就是安达网络工作室关于《WordPress 实现文章评论排行榜》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 评论 排行榜
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
wp-Syntax wordpress高亮插件应用办法

首先简略理解下 wp-Syntax 插件,wp-Syntax 是一个针对wordpress的代码高亮插件,最大的优点是简略易用,兼...

处理WordPress应用CDN后博文无奈评论的谬误

comments-ajax.js在cdn缓存后,很多人遇到无奈(应用ajax)回复的成绩。对此,我之前的做法只是制止cdn缓存...

WordPress装置应用Flowplayer繁难指南

本文是简略易懂的古代魔法系列文章的第二弹~ 一、Flowplayer简介 FlowPlayer 是一个用Flash开发的在Web上的...

WordPress中给文章增加自定义字段及后盾编辑性能区域

add_post_meta add_post_meta 函数是 WordPress 中用来给文章或页面增加自定义字段值的一个函数, 其用法与...

调用WordPress函数统计文章拜访量及PHP原生计数器的完成

1.首先引见WordPress的两款性能弱小的插件: (1)Count per Day 是一个十分弱小的访客数量统计插件,能够统...

在WordPress中应用PHP脚原本判别访客来自什么国度

区分访客国度有什么用&#63; 这里是几个我利用该性能的例子. 1.区分网站性能 这个博客有翻译文章的性能, 这是...

需求提交

客服服务