英雄榜单 – 每评论一次你就会自动排在前面

发现了一个好玩的功能:“英雄榜单 - 每评论一次你就会自动排在前面”,在此分享一下详细的操作步骤。

文章源自MAY的SEO博客-https://may90.com/building/hero.html

Step 1. 增加代码至functions.php

将下面的一段代码添加至functions.php的最下方,系统会自动调取最新前23个评论记录。具体多少个记录可以自行修改。文章源自MAY的SEO博客-https://may90.com/building/hero.html

//英雄榜单:每评论一次你就会自动排在前面
function getvisitors() {
    global $wpdb;
   // $query="select * from `wp_comments` where `comment_approved`=1 group by `comment_author_url` order by comment_ID DESC limit 0,23";
    $query="select MAX(`comment_ID`) comment_ID ,`comment_author_url`,`comment_author` from wp_comments 
where `comment_author_url`<>'' and `comment_approved`='1'  
group by `comment_author_url` order by `comment_ID`  DESC limit 0,23;";
    $sql = $wpdb -> get_results($query, ARRAY_A);
  
    //print_r($sql);
  
   
    foreach($sql as $vales){
  
    echo "<li><img src='hthttps://may90.com/wp-content/uploads/2019/02/timg-1.gif'><a target='_blank' rel='nofollow' href=".$vales["comment_author_url"].">".$vales["comment_author"]."</a></li>";
  
 }

}

Step 2. 在要展示的版块内容地方添加代码

May使用的是Begin主题,想要展示在banner的下方,所以直接在htdocs/wp-content/themes/begin/template/slider.php最下方添加一下代码。文章源自MAY的SEO博客-https://may90.com/building/hero.html

<div class="visitor">
<style>    
.visitor{width:100%;margin-bottom:10px;height:auto!important;background:#fff;text-align:center;color:#096cb2;
border:1px solid #ddd;border-radius:2px; padding-left: 20px;}
.visitor:hover {
    border: 1px solid #f2a900;
}
.visitor p{padding-top:4px;font-size:17px;}
.visitor ul{margin-top:10px;margin-bottom:10px;font-size:12px;padding-bottom:40px;}
.visitor ul li{list-style:none;float:left;margin-left:0px;margin-bottom:10px;width:16.6%;overflow:hidden;height:24px;text-align:left;}
.visitor ul li img{width:20px;height:20px;margin-left:2px;margin-right:2px;}
/*@media (max-width:900px) {.visitor{display:none}}*/
@media (max-width:900px) {
 .visitor ul li{width:25%;font-size:9px;} 
 .visitor p{padding-top:4px;font-size:15px;}
 
 }
</style>

<p>[英雄榜单] - 每评论一次你就会自动排在前面</p>
<ul>

<li><img src='https://may90.com/wp-content/uploads/2019/02/timg-1.gif'><a target='_blank' href=https://may90.com>MAY的SEO博客</a></li>

<?php 
 getvisitors();
?>

</ul>
<div style="clear: both;display:block"> </div>
</div>

经测试发现,电脑端和手机端均能正常显示。欢迎大家踊跃评论哟,你每评论一次就会自动展示在最前面哦。文章源自MAY的SEO博客-https://may90.com/building/hero.html


2019年5月24日补充:MAY的SEO博客已经取消了英雄榜,目的是将博客重心放在内容建设上。好的内容,自然会有读者评论。文章源自MAY的SEO博客-https://may90.com/building/hero.html

 文章源自MAY的SEO博客-https://may90.com/building/hero.html

 文章源自MAY的SEO博客-https://may90.com/building/hero.html 文章源自MAY的SEO博客-https://may90.com/building/hero.html

  • 我的微信
  • 扫一扫微信,添加好友
  • weinxin
  • 我的微信公众号
  • 关注公众号,了解最新动态
  • weinxin
  • 本文由 发表于 2019年2月12日
  • 转载请务必保留本文链接:https://may90.com/building/hero.html
评论  13  访客  8  作者  5
    • wordpress建站吧 6

      恭喜,有一个人用上了哈

      • typecho模板 2

        很好用

          • MAY的SEO博客

            @ typecho模板 谢谢访问,欢迎常来。

          • MDP BLOG 0

            你这东西有BUG,我再刷两会评论,你那英雄榜上面全是我名

              • MAY的SEO博客

                @ MDP BLOG 谢谢提醒。正在解决中。

                • wordpress建站吧 6

                  @ MDP BLOG 你前后2次的URL地址不一样导致的,如果对于恶意这样改名字改URL或改邮箱的,不好防备,

                • wordpress建站吧 6

                  group by `comment_author_url` 改成 group by `comment_author_email` 吧,有些人不是刻意的,但是2次的url地址不一样,所以出现了2次,这个按照填写的email来的,

                    • MAY的SEO博客

                      @ wordpress建站吧 已更改过来。但如果两次前些的邮箱不一样,是不是又会重复展示了。

                        • wordpress建站吧 6

                          @ MAY的SEO博客 是啊,不好避免那些故意的人。如果老喜欢这样搞的多半是来故意蹭流量的,那么可以后台管理评论里面修改他的信息或者删除啊,

                      • 浪子丶刘少 3

                        不知道为什么,我的Nana主题好想用不了,挺遗憾。。。

                        • 杂烩网 3

                          欢迎每天互访互评,本站的每评论一次排名第一覆盖全站!

                        发表评论

                        匿名网友 填写信息

                        :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

                        确定