怎样显示博客feed平均订阅阅读数
2010年8月22日
没有评论
一些博客,特别是一些国外的博客都用FeedBurner的chicklet来显示订阅数量,如果你想在你的博客上显示最近7天的平均订阅量,以下代码可以实现。
首先要做的是把以下代码添加到function.php文件中:
- function get_average_readers($feed_id,$interval = 7){
- $today = date('Y-m-d', strtotime("now"));
- $ago = date('Y-m-d', strtotime("-".$interval." days"));
- $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $feed_url);
- $data = curl_exec($ch);
- curl_close($ch);
- $xml = new SimpleXMLElement($data);
- $fb = $xml->feed->entry['circulation'];
- $nb = 0;
- foreach($xml->feed->children() as $circ){
- $nb += $circ['circulation'];
- }
- return round($nb/$interval);
- }

最新评论