Friday, 27 July 2012

HOW TO DISPLAY TWITTER FOLLOWERS AS TEXT

In a previous post I showed you to display your Feedburner Subscriber count as text, now here is the code to display your twitter followers as text.
STEP 1

Create a new file in your chosen code editor and copy and paste the following code into the file:

<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() - 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=handyHTML');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?>

Where on line 5 it says “handyHTML” change that to your Twitter User. Once that is done save the file as twitter-count.php, save the file into the root of your websites directory.
STEP 2

Now copy and paste the following code where you want the count to display, this calls the twitter-count.php file we created in Step 1 and outputs the total followers of the specified Twitter account.

<?php include("twitter.php"); ?>

STEP 3

Finally you can style your Twitter count, here is an example:

HTML

<p><span class="twitter-count"><?php include("twitter.php"); ?></span> Followers</p>

CSS

p {
color:#fff;
}

span.twitter-count {
font-size: 22px;
padding-left: 5px;
color: #1e7c9a;
}

…and voila! Come across any problems, comment and one of us will assist you.

Ditulis Oleh : Unknown // 21:46
Kategori:

0 comments:

Post a Comment

 

Followers

Powered by Blogger.