Problems? Solutions...
Problems
Apr 15th, 2010
Show some posts from your Twitter feed on your web site.
<div id=’twitter’>
<?php
$xml = "https://twitter.com/statuses/user_timeline/115146565.rss"; // Your Twitter RSS
$howMany = 5; // Tweets to show
$toReplace = "tensquirrel: "; // Text to strip from each item
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName(’channel’)->item(0);
$channel_title = $channel->getElementsByTagName(’title’)
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName(’link’)
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName(’description’)
->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo "
<p><a href=’$channel_link’ target=’_blank’><img src=’/_img/twitter25.png’ width=’25’ height=’25’ alt=’’ /></a><br />
<a href=’$channel_link’ target=’_blank’><strong>$channel_title</strong></a><br />
You should follow us!</p>";
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName(’item’);
for ($i=0; $i<$howMany; $i++)
{
$item_title=$x->item($i)->getElementsByTagName(’title’)
->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName(’link’)
->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName(’description’)
->item(0)->childNodes->item(0)->nodeValue;
$item_date=$x->item($i)->getElementsByTagName(’pubDate’)
->item(0)->childNodes->item(0)->nodeValue;
$item_desc = preg_replace( "/$toReplace/", "", $item_desc );
echo "
<p class=’note’>", findLinks( $item_desc ), "<br />
<em>", date( "M jS, h:ia", strtotime( $item_date ) ), "</em></p>";
}
?>
</div>
I place this in the header file on my site, and then style that <div> to be on the left rail. http://www.tensquirrel.com/work/ for an example.