Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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