How To Display Your Total Number Of Followers

22.06.09 by Jerome in Tutorials

How To Display Your Total Number Of Followers

If you are starting to be a rock star blogger and have 100 and 100′s of followers and subscribers, why not show to the world how many followers you have from your feed subscriber and Twitter followers. Of course you could use Feedburner or TwitterCounter script but why not create your own with just few lines of PHP. Thanks to Jean-Baptiste Jung from wprecipes.com for the solution.

Twitter Followers Count

Paste the following php code on your functions.php file:

function string_getInsertedString($long_string,$short_string,$is_html=false){
 if($short_string>=strlen($long_string))return false;
 $insertion_length=strlen($long_string)-strlen($short_string);
 for($i=0;$isaveHTML();
 $element->parentNode->removeChild($element);
 $html2=$document->saveHTML();
 return string_getInsertedString($html,$html2,true);
}
 
function getFollowers($username){
 $x = file_get_contents("http://twitter.com/".$username);
 $doc = new DomDocument;
 @$doc->loadHTML($x);
 $ele = $doc->getElementById('follower_count');
 $innerHTML=preg_replace('/^<[^>]*>(.*)<[^>]*>$/',"\\1",DOMElement_getOuterHTML($doc,$ele));
 return $innerHTML;
}

And simply paste the following code where you want the total number to show and replace pimpmywordpress with your Twitter username.

Feedburner Subscribers

Simply paste the following code where you wish:

<?php
$fburl=”https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=YourURL“;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $fburl);
$stored = curl_exec($ch);
curl_close($ch);
$grid = new SimpleXMLElement($stored);
$rsscount = $grid->feed->entry['circulation'];
echo $rsscount;
?>

No related posts.

feedburner, Tutorials, twitter, wordpress

Get More Wordpress Tips & Tricks

Liked this post? subscribe to our email updates or RSS feed!

Leave a Reply

Want your picture in comment? Go to gravatar.com & upload your preferred avatar for free.

blog comments powered by Disqus