Display X Number of Your Latest Twitter Entries


/ Published in: PHP
Save to your folder(s)

WordPress


Copy this code and paste it in your HTML
  1. <?php
  2. $username = "TwitterUsername"; // Your twitter username.
  3. $limit = "5"; // Number of tweets to pull in.
  4.  
  5. /* These prefixes and suffixes will display before and after the entire block of tweets. */
  6. $prefix = ""; // Prefix - some text you want displayed before all your tweets.
  7. $suffix = ""; // Suffix - some text you want displayed after all your tweets.
  8. $tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet.
  9. $tweetsuffix = "<br>"; // Tweet Suffix - some text you want displayed after each tweet.
  10.  
  11. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;
  12.  
  13. function parse_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
  14.  
  15. $feed = str_replace("&lt;", "<", $feed);
  16. $feed = str_replace("&gt;", ">", $feed);
  17. $clean = explode("<content type=\"html\">", $feed);
  18.  
  19. $amount = count($clean) - 1;
  20.  
  21. echo $prefix;
  22.  
  23. for ($i = 1; $i <= $amount; $i++) {
  24. $cleaner = explode("</content>", $clean[$i]);
  25. echo $tweetprefix;
  26. echo $cleaner[0];
  27. echo $tweetsuffix;
  28. }
  29.  
  30. echo $suffix;
  31. }
  32.  
  33. $twitterFeed = file_get_contents($feed);
  34. parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);
  35. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.