Created
July 1, 2012 17:38
-
-
Save willwade/3029056 to your computer and use it in GitHub Desktop.
How to display the latest tweet in your wordpress site
This file contains hidden or 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
#!/usr/local/bin/php.cli | |
<?php | |
/* to use. | |
1. Stick somewhere on your server. | |
2. Make sure the script can write to a file next to it (chmod 755 latest-tweet.txt) | |
3. Place into cron e.g. | |
*/15 * * * * /home/site/www/www/wp-content/themes/Moses/includes/twitter.php | |
4. Edit your footer (or anywhere) with this: | |
<?php echo file_get_contents(get_theme_root().'/Moses/includes/latest-tweet.txt'); ?></p> | |
<a href="http://twitter.com/YourUserName" id="followusontwitter">Twitter</a> | |
credits: http://www.wprecipes.com/how-to-display-your-latest-twitter-entry-on-your-wp-blog | |
*/ | |
// Your twitter username. | |
$username = "YourUserNameHere"; | |
// 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 = ""; | |
// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) | |
$suffix = ""; | |
$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); | |
return $tweet; | |
} | |
$twitterFeed = file_get_contents($feed); | |
$str = stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); | |
file_put_contents('latest-tweet.txt', $str); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment