Display the Latest Tweets from Multiple Authors
Display the Latest Tweets from Multiple Authors
The code mentioned in the above hack can actually be slightly modified so that it can support displaying the latest tweets from multiple users. The modification is rather simple, and still results in a snippet of self-contained PHP code. Place the following lines of code into a template file where the tweets should appear:
< ?php $usernames = “Profile1 Profile2 Profile3 Profile4”; // Usernames go here, separated by a space. $limit = “5”; // Define the maximum number of tweets to show $show = 1; // Change to 0 if account usernames should not be shown, leave set to 1 if they should be $prefix = “Our Latest Tweets”; // A prefix or heading for the tweets $prefix_sub = “”; //Prefix for each individual tweet $wedge = “”; // Separator between tweets $suffix_sub = “
“; // Appended to the end of every tweet
$suffix = “”; // This section of code will be added at the end of the entire list of tweets
function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) {
$usernames = str_replace(” “, “+OR+from%3A”, $usernames);
$feed = “http://search.twitter.com/search.atom?q=from%3A” . $usernames . “&rpp=” . $limit;
$feed = file_get_contents($feed);
$feed = str_replace(“&”, “&”, $feed);
$feed = str_replace(“< “, ““, “>”, $feed);
$clean = explode(““, $feed);
$amount = count($clean) – 1;
for ($i = 1; $i < = $amount; $i++) { $entry_close = explode(““, $clean[$i]);
$clean_content_1 = explode(““, $entry_close[0]);
$clean_content = explode(““, $clean_content_1[1]);
$clean_name_2 = explode(““, $entry_close[0]);
$clean_name_1 = explode(“(“, $clean_name_2[1]);
$clean_name = explode(“)“, $clean_name_1[1]);
$clean_uri_1 = explode(““, $entry_close[0]);
$clean_uri = explode(““, $clean_uri_1[1]);
echo $prefix_sub;
if ($show == 1) { echo “” . $clean_name[0] . “” . $wedge; }
echo $clean_content[0];
echo $suffix_sub;
}
}
echo $prefix;
parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub);
echo $suffix;
?>
Using the prefixes, the sub-prefixes, and the wedge variable, it’s possible to customize the above code pretty easily and make sure that it fits into any context within in an existing website’s design. Simply list all relevant Twitter usernames, separated by a space, and each will show their latest tweet within the defined limit set in the code.