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 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 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天评论最多日志

阅读剩余部分

相关阅读 >>

wordpress查询某年某月文章的sql语句

wordpress主题评论中添加回复的方法

wordpress中强大的调用文章函数query posts 用法

wordpress插件的使用

如何在本地安装wordpress

升级nginx支持http2服务端推送的方法

nginx设置wordpress伪静态的方法示例

wordpress添加前台注册功能的方法

wordpress 静态化设置 windows主机伪静态去除index.php方法

php date_default_timezone_set()设置时区操作实例分析

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...