Created
December 17, 2012 17:06
-
-
Save anonymous/4319896 to your computer and use it in GitHub Desktop.
If you have [Tweenest](http://pongsocket.com/tweetnest/) installed, then the following two functions will pull that data in to your WordPress install. This code assumes that the default table prefix is used (tn_).
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_tweetnest_tweets($args) { | |
global $wpdb; | |
$args = shortcode_atts(array( | |
'count' => 5, | |
), $args); | |
$sql = sprintf("SELECT `tn_tweets`.*, `tn_tweetusers`.`screenname`, `tn_tweetusers`.`realname`, `tn_tweetusers`.`profileimage` | |
FROM `tn_tweets` | |
LEFT JOIN `tn_tweetusers` ON `tn_tweets`.`userid` = `tn_tweetusers`.`userid` | |
ORDER BY `tn_tweets`.`time` DESC | |
LIMIT %d", $args['count']); | |
$tweets = $wpdb->get_results($sql); | |
$content = array(); | |
foreach($tweets as $tweet) { | |
$html = wptexturize($tweet->text); | |
$href = esc_url(get_twitter_status_url($tweet->screenname, $tweet->tweetid)); | |
$time = sprintf('%s ago', human_time_diff($tweet->time)); | |
$content[] = sprintf('<li>%s <a href="%s" class="tweet_time" rel="external">%s</a></li>', $html, $href, $time); | |
} | |
return sprintf('<div class="tweets"><ul>%s</ul></div>', implode("\r\n", $content)); | |
} | |
function get_twitter_status_url($username, $id) { | |
return sprintf('http://twitter.com/%s/status/%s', urlencode($username), urlencode($id)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment