Yes it is great that you can have a twitter follower button from many sites. But what if you are trying to make a very custom design where you want to place a code in text instead of using a button. Well then this tutorial is for you. In this tutorial we will show you how you can display the total number of twitter followers as text on your WordPress site.
Create a new file called twitter.php file located in your themes folder. Remember to make sure that you change WPBeginner to your username.
<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() – 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?>
Then simply paste this code any where you want in your theme files.
<?php include("twitter.php"); ?>
Now you can display the number of twitter followers on your WordPress site as text.
Source: Rarst
I get the following error message:
http://pastebin.com/iif9g35a
Could you help me figure out what's going wrong?
Thanks a lot!
- spam
- offensive
- disagree
- off topic
Like