Posted By

manavecplan on 09/12/10


Tagged


Versions (?)

Moste Recent Tweet


 / Published in: PHP
 

  1. function twitter_status($atts){
  2. extract(shortcode_atts(array(
  3. 'screenname' => '',
  4. 'count' => 1
  5. ), $atts));
  6. $transient = "$screenname"."_$count"."_twitter_status";
  7. $statuses = get_transient($transient);
  8. if ($statuses == true )
  9. {
  10. return $statuses;
  11. }
  12. elseif ($screenname != false)
  13. {
  14. $site = "http://twitter.com/statuses/user_timeline.json?screen_name=$screenname&count=$count";
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_URL, $site);
  18. $result = curl_exec($ch);
  19. $tweets = json_decode($result);
  20. foreach ( (array) $tweets as $tweet){
  21. $tweetcontent = $tweet->text;
  22. $newcontent = preg_replace('%@([^\s]*)%', "<a href="http://twitter.com/\\1">@\\1</a>", $tweetcontent);
  23. echo "<div class="twitter_shortcode"><p>
  24. <img class="twitter_shortcode_image" src="&quot;.esc_url($tweet-&gt;user-&gt;profile_image_url).&quot;"><span class="twitter_shotcode_username"><a href="http://twitter.com/&quot;.$tweet-&gt;user-&gt;screen_name.&quot;">".$tweet-&gt;user-&gt;screen_name."</a>&nbsp;�&nbsp;</span>$newcontent</p>
  25. </div>";
  26.  
  27. }
  28. $tweet_display = ob_get_clean();
  29. set_transient($transient, $tweet_display, 120);
  30. return $tweet_display;
  31. }
  32. else
  33. {
  34. return false;
  35. }
  36. }
  37.  
  38. add_shortcode('twitter_status', 'twitter_status');

Report this snippet  

You need to login to post a comment.