A Better Twitter Feed for Your Web Site
I have already posted a tutorial on How to Create a Twitter Feed on Your Web Site and I have been having a lot of emails in regards to people whose hosts do not allow URL file-access. Here is an alternative script that fetches and parses your Twitter RSS feed using a different function. Hopefully it will help out those who can’t use the other script.
The first thing you need to do is get your Twitter RSS feed URL. go to your Profile page and you will see a link in the bottom of your sidebar that says RSS feed. Click on this and then copy the URL. That will be your feed URL.
<ul> <?php $feedURL = "http://twitter.com/statuses/user_timeline/68559295.rss" // change to your feed URL $doc = new DOMDocument(); $doc->load($feedURL); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, ); array_push($arrFeeds, $itemRSS); } $limit = 5; for($x=0;$x<$limit;$x++) { $title = str_replace('bavotasan: ', '', $arrFeeds[$x]['title']); $str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $title); $pattern = '/[#|@][^\s]*/'; preg_match_all($pattern, $str, $matches); foreach($matches[0] as $keyword) { $keyword = str_replace(")","",$keyword); $link = str_replace("#","%23",$keyword); $link = str_replace("@","",$keyword); if(strstr($keyword,"@")) { $search = "<a href=\"http://twitter.com/$link\">$keyword</a>"; } else { $link = urlencode($link); $search = "<a href=\"http://twitter.com/#search?q=$link\" class=\"grey\">$keyword</a>"; } $str = str_replace($keyword, $search, $str); } echo '<li>'.$str.'</li>'; } ?> </ul> |
Twitter Bird icon provided by Loon Design.






i just love to Twitter everyday with my friends. Twitter is much better than blogging in my opinion and it is very addictive too.
–
Twitter is some ways is much better than blogging. I love to Twitter my everyday activities on my friends and relatives.
***
I like this commentary. Thanks for allowing it star in its own spot. I get uneasy when I encounter angry righteous mobs hurrying to open purses of feathers and burbly the tar. So often we understand only a tiny part of the write up and rather we let angriness do the thinking for us.
Hi I have this same problem, but I don’t exactly know where in the template I should make the changes for it to work. Should I change widget_twitter.php?
widget_twitter.php is where the Twitter widget code is stored. If you change that file, then you need to use the widget in your sidebar. Should fix it all up for you.
Thank you very much c.bavota. I tried to change it myself but got a parse error in PHP, supposedly on this line:$doc = new DOMDocument();
I’m not really good at PHP, so I don’t know where I should insert this code inside widget_twitter.php.
Could you tell me which part I should change? I really appreciate your help.
I just emailed you a solution.
Thanks, I’m trying to get this working now.