php按文章评论数排序,wordpress活跃访客按最近14天评论数排序的代码分享

bfd0d79376c025409b2051c36964d14c.png

wordpress活跃访客按最近14天评论数排序的代码分享

近期本站新增了一个小功能,就是读取展示了最14天评论数最多的前6个访客展示,这个功能的初衷也是想调用大家互动和评论的积极性,同时也方便互访。其实代码不难,自己下琢磨的,不一定合理规范,但是可用就行。

1、在主题的functions.php 文件中增加以下内容:

//2019年5月25日17:05:04添加 https://www.zouaw.com/

function getvisitors_top() {

global $wpdb;

$query="SELECT `comment_author`,`comment_author_url`,COUNT(`comment_ID`) AS tiao FROM `wp_comments`

WHERE `comment_author_url` NOT LIKE '%%' AND `comment_author_url` <>'' and DATE_SUB(CURDATE(), INTERVAL 14 DAY) <= date(comment_date) GROUP BY `comment_author_url` ORDER BY tiao DESC LIMIT 6";

$sqltop = $wpdb -> get_results($query, ARRAY_A);

$a=array("#2ba9fa","#ff6969","#67d4a7","#666","#2CDB87","#f1d71c");

foreach($sqltop as $key =>$vales){

//$random_keys=array_rand($a,1);

echo "

".$vales["comment_author"]."(".$vales["tiao"]."评)";

}

}

2、在需要增加显示的页面上合理位置增加如下代码:css一般主题可能不兼容需要自己改改:

.vistortop{width:100%;margin-bottom:20px;height:auto!important;background:#fff;border:1px solid #f5f9ff;text-align:center;color:#096cb2;

border:1px solid #eaeaea;border-radius:4px;}

.vistortop p{padding-top:4px;font-size:17px;}

.vistortop ul{margin-top:10px;margin-bottom:10px;font-size:13px;padding-bottom:40px;}

.vistortop ul li{list-style:none;float:left;margin-left:0px;margin-bottom:10px;width:16.03%;margin-right:5px;overflow:hidden;height:20px;

color:#fff;text-align:center;height:40px;line-height:40px;}

.vistortop ul li img{width:20px;height:20px;margin-left:2px;margin-right:2px;}

.vistortop ul li a{color:#fff;}

/*@media (max-width:900px) {.vistor{display:none}}*/

@media (max-width:900px) {

.vistortop ul li{width:32%;font-size:6px;height:30px;line-height:30px;margin-right:1%;overflow:hidden;padding-left:2px;padding-right:2px;

text-overflow:ellipsis;

white-space:nowrap}

.vistortop p{padding-top:4px;font-size:15px;}

}

[VIP宝座]-最近14天-按评论数排序

ea133b6885267e32a0db096cc96770db.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值