/ Published in: PHP

.twcounter {
background: #89B6F8;
padding: 10px;
color: #194B96;
}
background: #89B6F8;
padding: 10px;
color: #194B96;
}
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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>
Comments
