How to: Display twitter followers count on your blog/website

How to: Display twitter followers count on your blog/website

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 don’t like to install heavy plugins, that do little things like this. So decide to create a simple script to display the followers count. Yeah, it’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(''.$user_name.'.xml');
 $begin_tag = '';
 $end_tag = '';
 $first_part = explode($begin_tag,$tuser_info);
 $sec_part = explode($end_tag,$first_part[1] );
 $fcount = $sec_part[0];
 return $fcount;
 return '0';

This is the main function to get your twitter followers to count. Copy and paste it your common functions coded file like config.php, main_functions.php, engin.php, etc.. For 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 anywhere 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 username 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