知更鸟主题为评论者添加国籍、操作系统、浏览器和IP信息显示

发布时间:

知更鸟主题为评论者添加国籍、操作系统、浏览器和IP信息显示
知更鸟主题为评论者添加国籍、操作系统、浏览器和IP信息显示

1、下载:show-useragent(显示国籍系统浏览器文件))和 ip2c(显示运营商IP信息文件)

2、上传并解压到WordPress主题目录(解压后得到show-useragent文件夹和ip2c文件夹)

3、将show-useragent和ip2c引入到主题:

将以下代码放到主题目录下的functions.php中

  1. include("ip2c/ip2c.php");//IP归属地和运营商查询功能  
  2. include("show-useragent/show-useragent.php");//显示国籍、系统、浏览器信息

4、在需要显示的位置加入以下代码

  1. <span  class="ua-info">
  2. <?php
  3. CID_print_comment_flag();/*国籍*/
  4. echo ' ';/*空格*/
  5. CID_print_comment_browser();/*浏览器*/
  6. echo convertip(get_comment_author_ip());/*运营商*/
  7. ?>
  8. </span>

如:begin主题,则在主题目录下inc/comment-template.php文件,并找到以下代码,加在前面

  1. <span class="comment-meta commentmetadata">

添加后为:

  1. <span  class="ua-info">
  2. <?php
  3. CID_print_comment_flag();/*国籍*/
  4. echo ' ';/*空格*/
  5. CID_print_comment_browser();/*浏览器*/
  6. echo convertip(get_comment_author_ip());/*运营商*/
  7. ?>
  8. </span>
  9. <span class="comment-meta commentmetadata">

备注:如图标显示位置不对,在对应主题style.css文件内,加以下css代码调整

  1. /*调整留言者系统浏览器和运营商位置*/
  2.  .ua-info {
  3. margin-left:30px;
  4.  }
  5.  .WB-OS img{
  6.  vertical-align:-3px;
  7.  }

5、如需鼠标经过时显示或隐藏以上UA信息和IP地址,则在对应主题footer.php中添加代码:

  1. <script>
  2.     jQuery(function(){
  3.         $(".comment-body").hover(function(){
  4.             $(this).find(".ua-info").toggle();
  5.         },function(){
  6.             $(this).find(".ua-info").toggle();
  7.         });
  8.     });
  9. </script>

如果显示和隐藏效果相反,则在在对应主题style.css文件内或自定义CSS处,加以下css代码调整

  1. .ua-info {
  2.  display:none;/*设置隐藏*/
  3.   margin-left:8px;
  4. }