Yoast的Blog上介绍了一个利用Technorati API直接在Blog上显示排名的方法,原文为Using the Technorati API on your blog,此方法与之前介绍过的用字符方式显示Feedburner订阅数的方法类似,同样利用一段代码就可搞定。
个人感觉非常不错,所以马上试验了一下,现已能成功输出相应信息,具体使用方法如下。
1、首先到Technorati上获取你的API Key。
2、在Blog模版中添加如下代码:
注:红字部分需改为你自已的值。
<?php $technorati = get_option(”technorati”);
if ($technorati['lastcheck'] < ( mktime() - 600 ) ) {
$apikey = “apikey“;
$endpoint = “http://api.technorati.com/cosmos?key=”.$apikey;
$request = $endpoint.”&url=riku.me&limit=10″;
$snoopy = new Snoopy;
$result = $snoopy->fetch($request);
if ($result) {
$pattern1 = ‘/<inboundblogs>([0-9]+)</inboundblogs>/’;
$pattern2 = ‘/<inboundlinks>([0-9]+)</inboundlinks>/’;
$pattern3 = ‘/<rank>([0-9]+)</rank>/’;
preg_match($pattern1, $snoopy->results, $matches);
preg_match($pattern2, $snoopy->results, $matches2);
preg_match($pattern3, $snoopy->results, $matches3);
$technorati['inboundblogs'] = number_format($matches[1]);
$technorati['inboundlinks'] = number_format($matches2[1]);
$technorati['rank'] = number_format($matches3[1]);
$technorati['lastcheck']= mktime();
update_option(”technorati”,$technorati);
}
}
echo “<p>本Blog最近六个月内在”.$technorati['inboundblogs'].” 个Blog上有
“.$technorati['inboundlinks'].” 个外部链接,
在所有Blog中的排名为 “.$technorati['rank'].” .</p>”; ?>
3、查看自已的Blog显示效果。
本站位于Technorati上的信息:http://technorati.com/blogs/riku.me

Blog上的显示效果。

原作者文章:http://yoast.com/technorati-api-wordpress/
Technorati : api, rank, technorati
发表留言 原文链接 Feed订阅 F.ollow.me 乐涵
