在你的wordpress博客中显示你的Twitter关注者数量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在你的wordpress博客中显示你的Twitter关注者数量相关的知识,希望对你有一定的参考价值。
Add this snippet to the functions.php to render your twitter followers count.Replace 'planetabhi' with your twitter screen name
function my_followers_count($screen_name = 'planetabhi'){ $key = 'my_followers_count_' . $screen_name; // Let's see if we have a cached version $followers_count = get_transient($key); if ($followers_count !== false) return $followers_count; else { // If there's no cached version we ask Twitter $response = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name={$screen_name}"); if (is_wp_error($response)) { // In case Twitter is down we return the last successful count return get_option($key); } else { // If everything's okay, parse the body and json_decode it $count = $json->followers_count; // Store the result in a transient, expires after 1 day // Also store it as the last successful using update_option set_transient($key, $count, 60*60*24); update_option($key, $count); return $count; } } } echo "I have " . my_followers_count('planetabhi') . " followers";
以上是关于在你的wordpress博客中显示你的Twitter关注者数量的主要内容,如果未能解决你的问题,请参考以下文章