<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>derhofbauer.at / blog &#187; Twitter</title>
	<atom:link href="http://derhofbauer.at/blog/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://derhofbauer.at/blog</link>
	<description>bits, bites and beer for free</description>
	<lastBuildDate>Thu, 05 Jan 2012 12:08:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>AJAXed Twitter Plugin for WordPress</title>
		<link>http://derhofbauer.at/blog/ajaxed-twitter-plugin-for-wordpress/</link>
		<comments>http://derhofbauer.at/blog/ajaxed-twitter-plugin-for-wordpress/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 11:34:16 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://derhofbauer.at/blog/?p=63</guid>
		<description><![CDATA[Ricardo González wrote a nice plugin for WordPress that displays the public timeline of a twitter account in your WordPress theme. Though the plugin works I found two major problems: Sometimes Twitter doesn&#8217;t provide the timeline at first request. Embedding it in your theme significantly slows down loading of the blog. I came up with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rick.jinlabs.com">Ricardo González</a> wrote a nice <a href="http://rick.jinlabs.com/code/twitter/">plugin for WordPress</a> that displays the public timeline of a twitter account in your WordPress theme.</p>
<p>Though the plugin works I found two major problems:</p>
<ul>
<li>Sometimes Twitter doesn&#8217;t provide the timeline at first request.</li>
<li>Embedding it in your theme significantly slows down loading of the blog.</li>
</ul>
<p>I came up with a solution to both of them (featuring MooTools or jQuery support) using XMLHttpRequest.</p>
<p>Basically all it does is wait until the page is loaded and then request the tweets. If Twitter decides not to provide the timeline, the request is sent again until a configurable number of retries is reached.</p>
<p>There are two ways to use this plugin:</p>
<ol>
<li>Configure it manually (see how-to below)</li>
<li>Use it as a widget (version two and above)</li>
</ol>
<p>If you use it as widget, simply use the management functionality for widgets provided by WordPress. Otherwise (if your theme doesn&#8217;t support widgets for example) you can set also it up manually as I did on this blog (because I use MooTools here).<br />
<span id="more-63"></span></p>
<h3>Plugin setup:</h3>
<p>Provide a PHP-script (e.g. twitter.php in your theme folder), which can be loaded by the request:</p>
<div class="code">
<pre>if (!defined('DB_NAME')) {
	require_once("../../../wp-config.php");
}

echo AJAXedTwitter::messages(array(
	'username' => 'username'
));</pre>
</div>
<p>You can see I modified the original plugin to use an array instead of parameters (I hate functions that require more than 3 parameters).</p>
<p>Parameters for AJAXedTwitter::messages are:</p>
<table cellspacing="3">
<tr>
<th>Option</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr class="even">
<td>username</td>
<td>empty</td>
<td>the twitter username</td>
</tr>
<tr>
<td>num</td>
<td>5</td>
<td>number of tweets to show (limited to 20 by Twitter)</td>
</tr>
<tr class="even">
<td>list</td>
<td>true</td>
<td>show tweets in a unordered list</td>
</tr>
<tr>
<td>update</td>
<td>true</td>
<td>true show a relative timestamp</td>
</tr>
<tr class="even">
<td>linked</td>
<td>#</td>
<td>options for hyperlinks (see original plugin docs)</td>
</tr>
<tr>
<td>hyperlinks</td>
<td>true</td>
<td>true convert URLs to links</td>
</tr>
<tr class="even">
<td>twitter-users</td>
<td>true</td>
<td>show @username replies as links</td>
</tr>
<tr>
<td>encode-utf8</td>
<td>false</td>
<td>turn it on if you have encoding problems</td>
</tr>
<tr class="even">
<td>cache-age</td>
<td>1800 (half an hour)</td>
<td>expiry of the cached feed (tweets) in seconds, <code>-1</code> to disable</td>
</tr>
</table>
<h3>JavaScript-Setup:</h3>
<p>You have to tell the plugin which JS file to include (this should be done in wp_config.php):</p>
<div class="code">
<pre>define('AJAXED_TWITTER_FRAMEWORK', 'mootools');</pre>
</div>
<p>In this example the plugin will enqueue the twitter class for MooTools. If you don&#8217;t want to use it, you can also define <code>AJAXED_TWITTER_FRAMEWORK</code> to <code>false</code> and include our own scripts. The default value is <code>jquery</code>. It&#8217;s also possible to include both scripts (using &#8216;both&#8217;).</p>
<p>Please note that using the provided Twitter-class you have to <em>add MooTools to your theme&#8217;s header before <code>wp_head();</code></em>.</p>
<p>Then, below <code>wp_head();</code> add a script tag where you configure the twitter part:</p>
<div class="code">
<pre>var twitter = new Twitter('myTweets', {
&nbsp;&nbsp;url: '&lt;?php bloginfo('stylesheet_directory'); ?&gt;/twitter.php',
&nbsp;&nbsp;retries: 2,
&nbsp;&nbsp;animate: true
});
</pre>
</div>
<p>The above JS-code will automatically replace the element &#8220;myTweets&#8221; with your public timeline (or the error message if it runs out of retries) by loading the file twitter.php in your theme&#8217;s folder (see the PHP code?).</p>
<p>Possible options to the constructor are:</p>
<table cellspacing="3">
<tr>
<th>Option</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr class="even">
<td>url</td>
<td>null</td>
<td>the page to call, e.g. &#8220;/blog/wp-content/themes/derhofbauer/twitter.php&#8221;</td>
</tr>
<tr>
<td>retries</td>
<td>0</td>
<td>number of retries if first request fails</td>
</tr>
<tr class="even">
<td>animate</td>
<td>false</td>
<td>if true, tweets will be faded in</td>
</tr>
<tr>
<td>autostart</td>
<td>true</td>
<td>if false, you will have to trigger the first request using <code>twitter.request.send();</code></td>
</tr>
</table>
<h3>CSS classes:</h3>
<table cellspacing="3">
<tr>
<th>Class</th>
<th>Description</th>
</tr>
<tr class="even">
<td>twitter</td>
<td>the main list containing the tweets</td>
</tr>
<tr class="odd">
<td>twitter-item</td>
<td>list items (each tweet as li)</td>
</tr>
<tr class="even">
<td>first</td>
<td>the first list item</td>
</tr>
<tr class="odd">
<td>last</td>
<td>the last list item</td>
</tr>
<tr class="even">
<td>twitter-message</td>
<td>if not displaying as list and more than one tweets available, every tweet is put into a paragraph having this class</td>
</tr>
<tr class="odd">
<td>twitter-timestamp</td>
<td>spans containing the timestamp</td>
</tr>
<tr class="even">
<td>twitter-link</td>
<td>every detected link in the tweets</td>
</tr>
<tr class="odd">
<td>twitter-user</td>
<td>linked @replies</td>
</tr>
<tr class="even">
<td>twitter-error</td>
<td>displayed in case there was an error</td>
</tr>
</table>
<h3>Download:</h3>
<p><a href='http://derhofbauer.at/blog/wp-content/uploads/2010/01/ajaxed-twitter-for-wordpress-0.5.zip'>AJAXed Twitter for WordPress 0.5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://derhofbauer.at/blog/ajaxed-twitter-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

