让评论显示IP和所在地(1.9更新)

看2.7的wp后台时发现,管理评论那里多了显示IP(可能之前也有,是我没留意--!),突然想,要评论那里也显示留言者的IP吧。

翻了一下comment-temlate.php的函数,果然发现了显示IP的函数function comment_author_IP()

接下来要做的就是改评论的模板。找到你主题的comments.php页。在你想显示IP的地方(一般加在姓名后面)加上:

IP:<a href=”http://www.baidu.com/s?wd=<?php comment_author_IP()?>”><?php comment_author_IP()?></a>

链接是让百度帮你查找IP的地理位置。(因为找不到开放的IP数据库api,又不想再加多个数据库,所以只好这样--!)

------------更新分割线--------------------

原本沉了的贴子给挖了起来,于是又重新修改了一下,加多了根据IP显示所在地的功能。感谢vvp版主提供的查询接口。

代码修改如下:

IP:<?php $authorip = strval(get_comment_author_IP());
echo iconv(“gb2312″, “utf-8″,file_get_contents(“http://www.youdao.com/smartresult-xml/search.s?type=ip&q=$authorip”));?>

调用IP的函数换成了get_comment_author_IP(),转换成字符串后,修正编码,再利用有道搜索提供的IP查询来显示所在地。

效果:

ipip.jpg

16 thoughts on “让评论显示IP和所在地(1.9更新)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">