Last active
October 7, 2015 00:08
-
-
Save wokamoto/3074253 to your computer and use it in GitHub Desktop.
Twitterのツイートを表示する-RSS編
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> のつぶやき。</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