Posted By

florent on 10/21/11


Tagged

wordpress twitter


Versions (?)

Cached Twitter Follower Count


 / Published in: PHP
 

  1. function get_follower_Count(){
  2. $count = get_transient('follower_count');
  3. if ($count !== false) return $count;
  4. $count = 0;
  5. $data = wp_remote_get('http://api.twitter.com/1/users/show.json?screen_name=YOURNAME');
  6. if (!is_wp_error($data)) {
  7. $value = json_decode($data['body'],true);
  8. $count = $value['followers_count'];
  9. }
  10. set_transient('follower_count', $count, 60*60); // 1 hour cache
  11. return $count;
  12. }
  13.  
  14. Add the first section of code to the functions.php of your wordpress theme. This code will cache your Twitter follower number for 1 hour and display the count within your template.
  15.  
  16.  
  17. <?
  18. get_follower_count();
  19. ?>
  20.  
  21.  

Report this snippet  

You need to login to post a comment.