WordPressでTwitterのフォロワー数・ツイート数等を表示する
2013/2/10|
Category:
2016/11/26: この簡単な方法では情報が取得できなくなったようです。
今回は、ツイッターのアカウントの各種情報をWordPress(PHP)で表示する方法を紹介します。
STEP 1
以下のコードを「function.php」に記述してください。
その後、2行目の「id=」の後を表示したいTwitterのIDに変更し、不要な部分を削除してください。
function GetTwitterInfo(){ $url = "http://api.twitter.com/1/statuses/user_timeline.xml?id=自分のID"; $xml = simplexml_load_file($url); print $xml->status->user->name; //名前 print $xml->status->user->friends_count; //フォロー数 print $xml->status->user->followers_count; //フォロワー数 print $xml->status->user->statuses_count; //ツイート数 }
STEP 2
あとは、表示したい場所に以下のコードを記述してください。
<?php GetTwitterInfo(); ?>