The Better Way Display Twitter Followers in Text


Sponsored Links




There are so many ways to Display Twitter Followers in Text, the popular way is we can use CURL method, we have writen the tutorial display twitter followers in text using CURL. But this method for some WordPress Developers said this method not safe, because some server didn’t have CURL.

Twitter Land - Better Way Display Twitter Followers as Text

Twitter Land - Better Way Display Twitter Followers as Text

So after we check the tips from ProBlogDesign that you can read it here many famous developer has reply this post. The most interesting part is Otto one of Plugin Developer said that this method didn’t good. And here give more better. Otto using default WordPress function get_transient(); and wp_remote_get().

Display Twitter Followers in Text using Transients API

Write this code on your functions.php theme files and save it

function get_twitter_count() {
// first check the transient
$count = get_transient('follower_count');
if ($count !== false) return $count;

// no count, so go get it
$count = 0;
$data = wp_remote_get('http://api.twitter.com/1/users/show.json?screen_name=WPTricksNet');
if (!is_wp_error($data)) {
$value = json_decode($data['body'],true);
$count = $value['followers_count'];
}
// set the cached value
set_transient('follower_count', $count, 60*60); // 1 hour cache
return $count;
}

Please notes, you need to change username on the request, we have put WPTricksNet, so you need to put your own username. Next, you need to put the code to call this functions on your sidebar.php or whatever you want put the counter.

<?php echo get_twitter_count(); ?>

If you want style the code you can make like this example

<div class="twcounter"><?php echo get_twitter_count(); ?></div>

And you need add some style on your style.css

.twcounter {
background: #89B6F8;
padding: 10px;
color: #194B96;
}

That’s it, now you have better ways to Display Twitter Followers in Text, photos from flickr

Useful Source:

http://codex.wordpress.org/HTTP_API

http://codex.wordpress.org/Transients_API

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net


7 Responses to The Better Way Display Twitter Followers in Text

  1. Pingback: How To Display Twitter counter in Text # WordPress Tricks & Tips

  2. Pingback: Tweets that mention The Better Way Display Twitter Followers in Text # WordPress Tricks & Tips -- Topsy.com

  3. Pingback: Cara Menampilkan Jumlah Followers Twitter dengan Transients API

  4. Pingback: How to show the number of Twitter followers you have in WordPress » Malcolm Coles

  5. worked like a charm thanks! The one from problogdesign wouldn’t work for me. the function was never getting called.

  6. Jim Camomile says:

    OK, NOW THAT IS HELPFUL!!!
    After slogging through all the over bloated apps, plugins and ugly buttons just to display the number of twitter followers this gave me just what I needed and nothing more. Now I can style my button around this output and make it just the way I like it. Thanks for saving my day.

    Jim

  7. joreel says:

    Thanks for the codes, great tutorial I will try to figure out this and add my own functionality

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>