WordPress教程:给留言者增加UA信息和IP地址

站点建设89.7K字数 958阅读3分11秒阅读模式

这个原先是有搞过,但是都因为某些原因失败了。显示效果不理想,所以也就搁置了一段时间,如今记录下修改的过程,方便下次查看。

 文章源自亦枫博客-https://yflad.cn/1052.html

显示效果如图:文章源自亦枫博客-https://yflad.cn/1052.html

WordPress教程:给留言者增加UA信息和IP地址文章源自亦枫博客-https://yflad.cn/1052.html

 文章源自亦枫博客-https://yflad.cn/1052.html

1、把下面的文件下载了,解压后放在主题的目录下。文章源自亦枫博客-https://yflad.cn/1052.html

在此感谢张戈提供的源码文章源自亦枫博客-https://yflad.cn/1052.html

百度网盘提取码:[code]vtjn[/code](为防和谐)文章源自亦枫博客-https://yflad.cn/1052.html

 文章源自亦枫博客-https://yflad.cn/1052.html

2、将下面代码添加到wordpress主题根目录functions.php模板文件的最后:文章源自亦枫博客-https://yflad.cn/1052.html

  1. require get_template_directory() . '/show-useragent/show-useragent.php';

 文章源自亦枫博客-https://yflad.cn/1052.html

3、打开wordpress主题下的\inc\function目录的comment-template.php文件:文章源自亦枫博客-https://yflad.cn/1052.html

  1. <?php get_author_admin($comment->comment_author_email, $comment->user_id); ?>

下面添加:文章源自亦枫博客-https://yflad.cn/1052.html

  1. <span class="flags"><?php CID_print_comment_flag();echo ' ';CID_print_comment_browser(); echo convertip(get_comment_author_ip()); ?></span>

 文章源自亦枫博客-https://yflad.cn/1052.html

4、将下面配套样式文件添加到主题样式文件style.css最后:文章源自亦枫博客-https://yflad.cn/1052.html

  1. /* UA信息和IP地址 */
  2. .WB-OS img {
  3.     width14px;
  4.     heightauto;
  5.     vertical-align: -6%;
  6. }
  7. .flags {
  8.     displaynone;
  9. }
  10. @media screen and (min-width900px) {
  11.     .comment-body:hover .flags {
  12.         displayinline;
  13.         animation: fade-in;
  14.         animation-duration: 0.3s;
  15.         -webkit-animation: fade-in 0.3s;
  16.     }
  17. }

 文章源自亦枫博客-https://yflad.cn/1052.html

至此修改完毕,刷新下即可看到效果。如果有CDN,清理下缓存。文章源自亦枫博客-https://yflad.cn/1052.html

 文章源自亦枫博客-https://yflad.cn/1052.html 文章源自亦枫博客-https://yflad.cn/1052.html

继续阅读
扫扫关注公众号
weinxin
我的微信
扫扫体验小程序
weinxin
我的公众号
亦枫
  • 本文由 发表于 2017年9月3日 01:42:39
评论  8  访客  4  作者  4
    • 佛系软件
      佛系软件 1

      怎么在图标后面显示文字的呢

        • 亦枫
          亦枫

          @ 佛系软件 什么文字?自定义文字还是地区之类的?文字在第三步里添加即可

            • 佛系软件
              佛系软件 1

              @ 亦枫 就是图标+文字显示浏览器和系统版本,不要只显示图标

                • 亦枫
                  亦枫

                  @ 佛系软件 ,这个没有效果是吗?可能是api失效了哦

                    • 佛系软件
                      佛系软件 1

                      @ 亦枫 不是这个意思,我想要显示浏览器图标+浏览器名字和版本,系统图标+系统名字和版本,地址,运营商。你这个只有图标,但是文字必须鼠标放在上面才有显示,我想直接显示在图标的后面就像WP-UserAgent 插件那样的,不过这插件不能显示地址和ip

                    • 亦枫
                      亦枫

                      @ 佛系软件 样式去掉display: none;

                    • 佛系软件
                      佛系软件 1

                      @ 亦枫 你网站好像有问题,我评论显示Warning: time() expects exactly 0 parameters, 1 given in /www/wwwyflad/yflad/wp-content/themes/begin/functions.php on line 82

                匿名

                发表评论

                匿名网友 填写信息

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

                确定