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 评论 排行榜
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
修正WordPress链接程序和排序的办法

WP的性能弱小在于有支持并完满兼容的插件。自身WP链接治理不好自在排序,CoCo Link Sort 这款插件补偿了这样...

WordPress完成评论提交后跳转的办法

很多采纳WordPress顺序搭建的博客都相当注重与读者之间的互动,以评论为例,为了进步读者的体验品质,有的博...

WordPress评论增加楼层显示的办法小结

本文实例总结了WordPress评论增加楼层显示的办法。分享给大家供大家参考。详细剖析如下: 第一步:要在评论...

WORDPRESS文章中微信打赏性能的2种完成办法

本文实例讲述了WORDPRESS文章中微信打赏性能的2种完成办法。分享给大家供大家参考,详细如下: 打赏性能性能...

wordpress装置进程中遇到中文乱码的解决办法

在装置wordpress的时分,依照外面的readme.html的步骤进行装置,然而在拜访wp-admin/install.php的时分就呈...

wordpress正当利用wp-config.php文件小性能

这里有几个经过往wp-config.php中增加代码完成相干性能的技巧分享给大家。 1,去掉WordPress的历史修订版本...

需求提交

客服服务