Monday, November 26, 2012

Add a Twitter Follower Count to my Website


function twitter_count(){
         $count = get_transient('twitter_count');
    if ($count !== false) return $count;
         $count = 0;
         $dataOrig = file_get_contents('http://twitter.com/users/show/wpforce');
   if (is_wp_error($dataOrig)) {
         return 'Error!!!';
   }else{
         $profile = new SimpleXMLElement ( $dataOrig );
         $countOrig = $profile->followers_count;
         $count = strval ( $countOrig );
         }
set_transient('twitter_count', $count, 60*60*24); // 24 hour cache
return $count;
}
To use this function, simple echo it wherever you want it.
<?php echo twitter_count(); ?>

Visit www.DFWAdGenius.com for more information on adding followers

No comments:

Post a Comment