存档

文章标签 ‘feed’

怎样显示博客feed平均订阅阅读数

2010年8月22日 没有评论

一些博客,特别是一些国外的博客都用FeedBurner的chicklet来显示订阅数量,如果你想在你的博客上显示最近7天的平均订阅量,以下代码可以实现。

首先要做的是把以下代码添加到function.php文件中:

  1. function get_average_readers($feed_id,$interval = 7){
  2. $today = date('Y-m-d', strtotime("now"));
  3. $ago = date('Y-m-d', strtotime("-".$interval." days"));
  4. $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_URL, $feed_url);
  8. $data = curl_exec($ch);
  9. curl_close($ch);
  10. $xml = new SimpleXMLElement($data);
  11. $fb = $xml->feed->entry['circulation'];
  12.  
  13. $nb = 0;
  14. foreach($xml->feed->children() as $circ){
  15. $nb += $circ['circulation'];
  16. }
  17.  
  18. return round($nb/$interval);
  19. }

阅读全文…

WordPress Hack:在RSS Feed中显示缩略图

2010年6月24日 33 条评论

将以下代码复制粘贴到functions.php,你的WordPress博客rss feed 中将显示你博客中图片的缩略图。

  1. function diw_post_thumbnail_feeds($content) {
  2. global $post;
  3. if(has_post_thumbnail($post->ID)) {
  4. $content = '
  5. <div>' . get_the_post_thumbnail($post-&gt;ID) . '</div>
  6. ' . $content;
  7. }
  8. return $content;
  9. }
  10. add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
  11. add_filter('the_content_feed', 'diw_post_thumbnail_feeds');