Copy and paste this code anywhere in your website
originally posted by http://www.wprecipes.com/how-to-display-your-latest-twitter-entry-on-your-wp-blog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php // Your twitter username. $username = "username"; // Prefix - some text you want displayed before your latest tweet. // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\") $prefix = " <i>(Last Twitter post) <b><A Target='_Blank' HREF='http://twitter.com/" . $username . "'>"; // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) $suffix = "</a></b></i>"; $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet = str_replace(">", ">", $tweet); $tweet = str_replace("&quot;", "'", $tweet); return $tweet; } $twitterFeed = file_get_contents($feed); echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); ?> |