I’ve tried about 15 different variations of code to try and get this working to no avail. Basically all I want on my WordPress site is my latest tweet. The code below is from Smashing Magazine and obviously in my code I have changed $username to my Twitter username. Nothing has worked so far, and I’m at a loss as to what it is. It is connecting to Twitter because it takes much longer to load the page when the code is there. I’ve also tried one which showed me how many followers I had and displayed my username but didn’t show my tweet. This is my website if it helps at all…
http://newmedia.leeds.ac.uk/ug10/cs10cwh/wordpress/
I’ve removed the code for the minute to speed up loading time. Any help would be much appreciated.
<?php
// Your twitter username.
$username = "TwitterUsername";
// 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 = "<h2>My last Tweet</h2>";
// 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);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
There is no problem with the code.
Possibility 1: you have provided a wrong/invalid
$username.Possibility 2:
file_get_contentsis not retrieving the contents. (due to PHP settings, network issues, or something else)