There are lots of resources out there for displaying your latest twitter posts in your website. Some of them require plugins or some may require javascript to work. After trying a few scripts I came across a little PHP script from The Lylo Files that displays up to 20 of your posts on your web site. After using it for a little while I decided to make it more functional.

This script has been depreciated in favor of the the new Twitter API. Check out Display your Cached Tweets Using PHP and OAuth

The list of changes from the original are:

  • #Hashtags are now clickable.
  • Changed @reply to include _ underscores and – as many user-names contain these.
  • Added retrieval of published date and its associated link.
  • Split the date up so that you can have many different variants like Thu 10 Sep or Sep 10 2009, etc.

Setup

It is pretty simple to setup just copy and paste the above code into your site, change worldoweb to your twitter username and change the $max_tweets to anything between 1 and 20. The default output, in line 51, displays the link at the beginning of the tweet wrapped in bold, strong tags.

Display twitter post on your site

To display the date at the end, change line 51 to:

echo "<li class='tweet'>". $tweet . "<strong>". "<a rel="nofollow" href='$link' target='blank' title='$title'>" . $ddmmyy."</a>" . "</strong>" . "</li>n";

Display twitter post on your site

You can of course remove the link altogether.

echo "<li class='tweet'>" . "<strong>" . $ddmmyy . "</strong>" . $tweet . "</li>n";

The change the date format string in the tweet (line 51) you can change the default $ddmmyy to any of the following.

  • To display the date like 09 Sep change it to $ddmm
  • To display the date like Sep 09 change it to $mmyy
  • To display the date like Sep 09 2009 change it to $mmddyy
  • To add the day of the week to these use $day.$mmyy.

I hope you enjoyed this script and I would like to thank the original author of the script for making this possible. I would love to hear all of your comments so don’t be shy.