Return to Snippet

Revision: 43957
at April 4, 2011 07:07 by alexeihidalgo


Updated Code
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('<a href="http://api.twitter.com/1/users/show.json?screen_name=WPTricksNet" rel="nofollow">http://api.twitter.com/1/users/show.json?screen_name=WPTricksNet</a>');
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;
}

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

Revision: 43956
at April 4, 2011 07:04 by alexeihidalgo


Initial Code
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('<a href="http://api.twitter.com/1/users/show.json?screen_name=WPTricksNet" rel="nofollow">http://api.twitter.com/1/users/show.json?screen_name=WPTricksNet</a>');
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;
}

Initial URL


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

Initial Title
Display Twitter Followers in Text

Initial Tags


Initial Language
PHP