Get Feedburner Count Using Get_Transient and Wp_Remote_Get


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function feed_subscribers(){
  2. $feed_url = 'http://feeds.feedburner.com/yourname';
  3. $count = get_transient('feed_count');
  4. if ($count != false) return $count;
  5. $count = 0;
  6. $data = wp_remote_get('http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='.$feed_url.'');
  7. if (is_wp_error($data)) {
  8. return 'error';
  9. }else{
  10. $body = wp_remote_retrieve_body($data);
  11. $xml = new SimpleXMLElement($body);
  12. $status = $xml->attributes();
  13. if ($status == 'ok') {
  14. $count = $xml->feed->entry->attributes()->circulation;
  15. } else {
  16. $count = 300; // fallback number
  17. }
  18. }
  19. set_transient('feed_count', $count, 60*60*24); // 24 hour cache
  20. echo $count;
  21. }
  22.  
  23. Then add this to your WordPress theme in the location you wish to display the RSS feed subscriber count.
  24.  
  25.  
  26. <? feed_subscribers(); ?>
  27.  
  28.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.