- Subscribe and get the new articles every now and then directly in your reader — I recommend using Google Reader
Display Twitter timeline in Expression Engine - Part 1
Read comments ‣ (3)
written by Marek Foss
You probably noticed on the right, there are my latest Twitter messages (you could follow me, too :). There are generally two ways to fetch tweets into Expression Engine (EE). One involves using a plugin to directly access your Twitter account and display messages. The other is about monitoring your feed (or any other, in fact) and pushing new messages to a special EE weblog. Today, I will focus on the first, simpler method.
First, you need to grab a Twitter plugin, for example the Twitter Timeline developed by the EE team. The usage is easy, you just upload the contents to the plugin folder and activate the plugin in the Plugin Manager located in Utilities. One drawback of this plugin is that you have to explicitly type your Twitter password in the template.
{exp:twitter_timeline type="friends" user="email@example.com" password="password1"}
It is not a big issue if you run your EE alone, but in a group weblog it may be a problem. If so, wait for the Part 2 of my description — feed-based method. Another issue is that by default, the plugin does not convert URLs to clickable links. The plugin on the EE site downloads doesn’t seem to have any option to turn auto-converting on, but you could find a modified version on EE forums. Or you could just make a small modification I came up with — locate the line 184 and modify the if-condition as shown, adding a regular expression, which makes the links clickable.
184. if ($count > $this->limit)
185. {
186. $output = preg_replace("/(?<!<a href=\")((http|ftp)(s)?:\/\/[^<>\s]+)/i", "<a rel=\"nofollow\" href=\"\\0\">\\0</a>", $output );
187.
188. return $output;
189. }
What the regular expression does, is it looks for occurrences of HTTP, FTP, HTTPS or FTPS and the :// symbols, and retrieves the URL address. Then it swaps that with an HTML a href element linking to that retrieved URL. Hence, you get clickable links.
After you insert the exp:twitter_timeline tag in your template, you will have your Twitter timeline fetched straight to your weblog. And then you can write long posts using EE, as well as short messages with Twitter, both at one place for your readers to have a look at.
Comments
Nice one! Very useful… Especially getting the links to work. Cheers
Thanks!
Another useful hack that fits right underneath yours makes @names into links.
$output = preg_replace('/@(\S+)/', '<a rel="nofollow" href="http://www.twitter.com/' . ">@' . "$1" . '</a>', $output);


