Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active October 7, 2015 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/3074253 to your computer and use it in GitHub Desktop.
Save wokamoto/3074253 to your computer and use it in GitHub Desktop.
Twitterのツイートを表示する-RSS編
<?php
function get_tweet_lines($userName){
date_default_timezone_set('Asia/Tokyo');
$rssUrl = 'http://twitter.com/statuses/user_timeline/'.$userName.'.rss';
// get cache
if ( ($response = get_transient(md5($rssUrl))) === false ) {
$response = wp_remote_get($rssUrl);
if( !is_wp_error( $response ) && $response["response"]["code"] === 200 ) {
set_transient(md5($rssUrl), $response, 60 * 60 ); // 60sec * 60min = 1hour
} else {
$response = false;
}
}
if( $response && !is_wp_error($response) ) {
$rssData = simplexml_load_string($response["body"]);
echo '<ul id="vertical-ticker" class="tweet-widget">';
foreach($rssData->channel->item as $item){
$pubDateJP = date("Y/m/d H:i:s",strtotime($item->pubDate));
echo "<li>".str_replace("\n",'',$item->description)."<p><a href='".$item->link."'>".$pubDateJP."</a>&nbsp;のつぶやき。</p></li>\n";
}
echo '</ul>';
} else {
// Handle error here.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment