If you don’t like the Twitter Counter Badge provided by TwitterCounter and you want to display your Twitter counter in plain text, actually it is easy. You can just follow the below simple step to do it.
1. Add the following code to functions.php.
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;$i<strlen($short_string);++$i){
if($long_string[$i]!=$short_string[$i])break;
}
$inserted_string=substr($long_string,$i,$insertion_length);
if($is_html && $inserted_string[$insertion_length-1]=='<'){
$inserted_string='<'.substr($inserted_string,0,$insertion_length-1);
}
return $inserted_string;
}
function DOMElement_getOuterHTML($document,$element){
$html=$document->saveHTML();
$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;
}
2. Copy and paste the following short code to anywhere on your theme files, remember replace your twitter username.
<?php echo getFollowers("yourtwitterusername")." followers"; ?>
/images/logo.png)
/images/featured.png)
/images/recentposts.gif)
/images/ico-rss.gif)
/images/cat.png)
Is it possible to get ones twitter-feed in plain-text?
Frederick, i think i’ve seen it done but don’t know how or what work around they used. i’ll look around since i had this question before as well. if you find out first please let me know
[...] 28. Blogging Secret [...]
[...] your feedcount in a random sentence How to Display Twitter Count in Plain Text WordPress 2.9 Enhancements Every Developer Must Know How To Display Smooth Slider On The Home Page [...]
i always update my Twitter and i love to twitter my daily activities to my friends and loved ones. i also maintain a personal blog for entries which requires more detail.
thanks for the script,
i would like to get a list of all my followers, anybody know how 2 do ?
Kind regrards from Holland
It’s the first time I seach this site and I am really enthusiastic about so many fantastic articles. I think it is just very well.
Hello! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating my own but I’m not sure where to start. Do you have any points or suggestions? Thank you
This is the great and nice read. Your blog is written such it’s so easy to read and understand. I’m a lover of your site. Thank you giving this information.