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
<!--?php <br ?--> function tf_count($user_name='')
$tuser_info = file_get_contents('http://api.twitter.com/1/users/show/'.$user_name.'.xml');
$begin_tag = '';
$end_tag = '';
$first_part = explode($begin_tag,$tuser_info);
$sec_part = explode($end_tag,$first_part );
$fcount = $sec_part;
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:<!--?php echo tf_count('lineshjose');?-->.
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