For a long time I have not in this blog and on my blog write due to the hustle and bustle of the offline world. Because I back online cannot assume I want to write :) back here.


As the title says, shows our Twitter followers with PHP. We know almost all blogs that explain, Web development and design is this, as well as other professional blog blog.


There are many plugins that the number of supporters simply can appear, but what is the damage if we can make it yourself? in this way we could make out some of the crowd, and we can customize the appearance with CSS.


Peter Ivanov made a PHP function, which is useful, :) for us. But before we move on to the PHP application session I would like to remind that.



Back up the PHP file that will be on the change and it first XAMPP is good, if you first try it on localhost server on your computer, or you can use WAMP


PHP function that we add to the functions.php


You must place first below the function of PHP in your WordPress directory, you can use it on .../htdocs/wp-includes/functions.php

/ * * You get the number of followers from Twitter api * @ author Peter Ivanov * @ copyright http://www.ooyes.net * @ version 0.2 * @ link http://www.ooyes.net * @ param string $ username * @ return string * / function Twitter_followers_counter ($ username) {$ Cache_file CACHEDIR =.} Twitter_followers_counter '_'. MD5 ($ username); If (Is_file ($ Cache_file) == false) {$ Cache_file_time = Strtotime (' 1984-01-11 07:15 pm ');} else {$ Cache_file_time = Filemtime ($ Cache_file);} $ now = Strtotime (date (' Y-m-d H: i: s ')); $ Api_call = $ Cache_file_time; $ Difference = $ now$ Api_call, $ Api_time_seconds = 1800; If ($ difference & gt; = $ Api_time_seconds) {$ Api_page = 'http://twitter.com/users/show/'. $ username; $ XML = File_get_contents ($ Api_page); $ profile = new SimpleXMLElement ($ XML); $ count = $ profile & gt;} Followers_count; If (Is_file ($ Cache_file) == true) {remove ($ Cache_file);}Touch ($ Cache_file); File_put_contents ($ Cache_file, Strval ($ count)); {return Strval ($ count);} {Else {$ count = File_get_contents ($ Cache_file); return Strval ($ count);}}

To display the number of actual supporters just template files do this anywhere in your:


Description


This function call the Twitter API and get information about the followers of a specific user name, and save the result in a cache, so that Penghitungannya is not computed every time was when reset a page in the free, which generate a lot of calls API request occurred.


Indicate your followers


Since we write functions that are provided by Peter Ivanov we add the following code live, was placed under to your template and displays the number of followers.

Print Twitter_followers_counter ($ Twitter_name);

And don't forget the $ Twitter_name to replace with your Twitter user name. In the example, the number of followers will show I could write code like below.

Print Twitter_followers_counter ('Ootofthebox');


NB: I'm sorry, I can give you no screenshots, because my site is still in the stage of processing, and once again remember Please secure your functions.php and you try it first on localhost computer/laptop.


The conclusion of


It turns out that PHP code makes the number of supporters, we are not too hard, right? We need not a professional developer, to do so. Now you already have PHPnya is like your creativity to Menghiasanya with a little CSS code:)


If you want to share something either alternative is an easier way, suggestions, criticism, feel free to post-it :) BRO here I get any comments, criticism, Maki verbaland proposals:)