It is great that you can have a twitter follower button on your website or blog. Some bloggers or developers, using heavy plugins to show their twitter followers count on their website.
In this note, I will show you how you can display the total number of twitter followers as text on your blog or websites.
I really don’t like to install heavy plugins, that do little things like this. So decide to create a simple script for display the followers count. Yeah, its’s done. This code is very simple. I think, it’ll be very helpful for you.
step 1: Adding code to your site
function tf_count($user_name='') { if($user_name) { $tuser_info = file_get_contents('http://api.twitter.com/1/users/show/'.$user_name.'.xml'); $begin_tag = '<followers_count>'; $end_tag = '</followers_count>'; $first_part = explode($begin_tag,$tuser_info); $sec_part = explode($end_tag,$first_part[1] ); $fcount = $sec_part[0]; return $fcount; }else{ return '0'; } }
This is the main function to get your twitter followers count. Copy and paste it your common functions coded file like config.php, main_functions.php, engin.php etc.. For an example: WordPress uses the function.php file to write common custom functions for particular themes. If you are a WordPress blogger open functions.php, paste this script and save the file.
step 2: Display Followers count
Now simply call that function any where you want in your theme files. For an example: I like to show my twitter followers count on my blog’s header, I simply calling that function with my twitter user name in header.php file, like this.
Twitter: <strong><?php echo tf_count('lineshjose');?></strong>.
Isn’t it simple?..
Note: Please ask your host provider to enable file_get_contents() feature in your server, if you getting an error like this,
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /[.....]/t_count/index.php on line 6
Happy blogging





Thanks for this sample it really helps.
Thanks a lot. I was searching for this thing for last 1 week. Thanks Again!
This is the exact thing I am searching for last few hours.. the next thing I need to figure out is a way to display FB Likes as text.
its really helpful but i want to display the name of the followers ,how to display that thing,and which twitter api is used for it plz help me out
Raj, Use this script http://lineshjose.com/blog/how-to-display-twitter-followers-list-on-your-blog/ to display the followers.