I'm a site optimization freak and displaying my latest tweets with the usual code snippet was adding an other javascript to my website, so I searched for an other way of doing it, sans JavaScript. There were probably WordPress plugins for this but I hate having to install too much plugins. The first Google results do the job just fine... for english speakers. If you have special characters or accents, some PHP code won't show them properly.
I have found the solution on NickHeer.com ! Go to this page to get the code to display your latest tweets very simple with PHP or grab it here :
<?php
$username = "your username";
$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 = htmlspecialchars_decode($tweet,ENT_QUOTES);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo('"'.parse_feed($twitterFeed).'"');
?>
You just have to edit your username on line 2 before using it !


on October 6, 2010
at %I:%M %p
Salut Darine,
Le hack fonctionne impeccable. Par contre, j'ai deux questions:
- la première: comment afficher X tweets ?
- la seconde (à deux balles): supprimer les guillemets ?
Merci d'avance ;-)
on October 6, 2010
at %I:%M %p
Hello,
pour afficher X tweets essaie de remplacer &rpp=1 par &rpp=X
pour enlever les guillemets, remplace
echo('"'.parse_feed($twitterFeed).'"');
par
echo(parse_feed($twitterFeed));
on October 7, 2010
at %I:%M %p
Re Karine,
J'avais essayais de remplacer cette valeur déjà, ça ne fonctionne pas... :/
Par contre pour les guillemets c'est bon :-)
on May 9, 2011
at %I:%M %p
Hello! Can somebody please help me with this? I can get this code to work 100% fine with every twitter account that I try... EXCEPT for the one that I am supposed to be using for it (@cominsteahouse). They have tweeted recently - I have even tried it with other usernames who tweeted longer ago than my client and it works. I don't understand why it won't work??
Btw I am installing in the footer of a Magento ecommerce shop.
Any advice gratefully received!!