<?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>Richard Shepherd &#187; tweet</title>
	<atom:link href="http://www.richardshepherd.com/tag/tweet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardshepherd.com</link>
	<description>Making the web. Better looking.</description>
	<lastBuildDate>Fri, 04 Jun 2010 18:03:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The 7 Things I Hate About You&#8230; Yes You, Twitter!</title>
		<link>http://www.richardshepherd.com/the-7-things-i-hate-about-you-yes-you-twitter/</link>
		<comments>http://www.richardshepherd.com/the-7-things-i-hate-about-you-yes-you-twitter/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 21:25:58 +0000</pubDate>
		<dc:creator>richardshepherd</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[7 things]]></category>
		<category><![CDATA[miley cyrus]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.growlingranger.com/?p=467</guid>
		<description><![CDATA[I think we can all agree that Miley Cyrus is one of the most influential recording artists of our time. Probably. So, in an homage to her and Ken Jones &#8211; and all those Top 10 (7?) lists out there on Twitter &#8211; here is my own list. Yes Twitter, these are the seven things [...]]]></description>
			<content:encoded><![CDATA[<p>I think we can all agree that Miley Cyrus is one of the most influential recording artists of our time. Probably.</p>
<p>So, in an homage to her and <a href="http://www.seopscentre.com/personal/7-things-i-hate-about-memes/" target="_blank">Ken Jones</a> &#8211; and all those Top 10 (7?) lists out there on Twitter &#8211; here is my own list.</p>
<p>Yes Twitter, these are the seven things I hate about you&#8230;<span id="more-467"></span></p>
<ol>
<li><strong>You&#8217;re vain, your games, you&#8217;re insecure</strong> &#8211; Let&#8217;s face it Twitter. Everyone on Twitter loves talking about Twitter. And why? Because we want to justify the amount of time we spend on it!</li>
<li><strong>You love me, you like her</strong> &#8211; I think that everyone is listening to me, but they&#8217;re not. They&#8217;re listening to everyone else. Damn you Twitter, you&#8217;ve made me your bitch!</li>
<li><strong>You make me laugh, you make me cry</strong> &#8211; Okay, so I haven&#8217;t cried yet but I know it&#8217;s not far away. The first time I see that Fail Whale I&#8217;m going to bawl my eyes out like a schoolgirl who just lost her Tweeting Barbie.</li>
<li><strong>I don&#8217;t know which side to buy</strong> &#8211; Do I Tweet because I want to learn about cool sites? Do I really want to know what a bunch of strangers are doing? Or do I Tweet because it fills up my otherwise empty life with &#8216;followers&#8217; assuming that they&#8217;re also friends?</li>
<li><strong>Your friends, they&#8217;re jerks.  When you act like them, just know it hurts</strong> &#8211; All those auto-DMers. I thought I had hundreds of friends, but they disappear as quickly as they appear. Is nothing what it seems? Bunch of fucking jerks.</li>
<li><strong>I wanna be with the one I know</strong> &#8211; Oh Twitter, bring me comfort. Bring me company on those cold winter evenings. Tell me that I&#8217;m yours and yours alone. Ruffle those sexy blue feathers and tell Tweetdeck to &#8216;coo&#8217; me another message.</li>
<li> <strong>And the 7th thing I hate the most that you do. You make me love you</strong> &#8211; Damn you Twitter. Damn you I say!</li>
</ol>
<p>And I think that&#8217;s conclusive proof. About what I&#8217;m not sure, but thank God Miley isn&#8217;t on Twitter.</p>
<p>She&#8217;s not, is she?</p>
<p>Ranger, out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardshepherd.com/the-7-things-i-hate-about-you-yes-you-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to write a WordPress Twitter Widget &#8211; Part 2 of 3</title>
		<link>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-2-of-3/</link>
		<comments>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-2-of-3/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 15:00:29 +0000</pubDate>
		<dc:creator>richardshepherd</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[Wordpress Plugin]]></category>

		<guid isPermaLink="false">http://www.growlingranger.com/?p=363</guid>
		<description><![CDATA[Welcome back! So you should have read through part one of the tutorial, where we left things off with the following line of code: $result = $t -&#62; userTimeline&#40;$id=false, $count = &#40;$options&#91;'tweets'&#93; * 4&#41;, $since = false&#41;; (If that looks strange, make sure you check out part 1 of this tutorial!) We now have our [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome back! So you should have read through part one of the tutorial, where we left things off with the following line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$t</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">userTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweets'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(If that looks strange, make sure you <a href="http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-1-of-3/">check out part 1</a> of this tutorial!)</p>
<p>We now have our Tweets stored in <strong>$result</strong> so we can just cycle through them and print them out in our widget. To do that we need the next bit of code.</p>
<p>Rather than explain each line after the code, I have heavily commented it which takes you through the process step-by-step&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// If there are no results, lets pop up a default message</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">===</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Sorry, nobody's home! Back in five.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Success! We have Tweets! Let's display 'em!</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// First we grab our CSS stylesheet. It's a really simple one, but it's good practice to</span>
<span style="color: #666666; font-style: italic;">// keep this in a seperate file.</span>
<span style="color: #b1b100;">echo</span><span style="color: #0000ff;">'&lt;link href=&quot;'</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/wp-content/plugins/WordTweet/WordTweet.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// We need a way to count the number of Tweets we display, so let's start a counter at '0'.</span>
<span style="color: #000088;">$iTweets</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The first piece of HTML. The &lt;div&gt; class 'WordTweet' is there for our CSS styling</span>
<span style="color: #666666; font-style: italic;">// The &lt;ul&gt; unordered list is how we'll be displaying each Tweet</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;WordTweet&quot;&gt;&lt;ul&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// For each part of the array, in other words each Tweet, we grab the</span>
<span style="color: #666666; font-style: italic;">// string and call it $tweet</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// We're interested in the text within the Tweet, not the other</span>
<span style="color: #666666; font-style: italic;">// information like date (until later!). Let's grab that and call it $message.</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$tweet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Now I like to take our any Tweets beginning with '@', as these are replies specifically</span>
<span style="color: #666666; font-style: italic;">// to other people. If you wanted you could take this bit out, but don't forget to remove the</span>
<span style="color: #666666; font-style: italic;">// closing '}'</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;@&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iTweets</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweets'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// make_clickable is a helpful WordPress function that takes things like email addresses</span>
<span style="color: #666666; font-style: italic;">// and websites in a string of text and turns them into links. Ah, the joy of regular</span>
<span style="color: #666666; font-style: italic;">// expressions!!</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> make_clickable<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// I don't display the first, as it's in the header of my theme, so I skip the first Tweet</span>
<span style="color: #666666; font-style: italic;">//by making sure that $iTweet is greater than 0.</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iTweets</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// You could take this line out...</span>
<span style="color: #666666; font-style: italic;">// Display the Tweet, nestled in a &lt;li&gt;&lt;/li&gt; tag</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// ...but you'd need to remove this too!</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// That's one Tweet down, so let's increase $iTweet by 1</span>
<span style="color: #666666; font-style: italic;">// and move on to the next</span>
<span style="color: #000088;">$iTweets</span><span style="color: #339933;">++;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// End of the If statement</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// End of the foreach loop</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Finish up our HTML output</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ol&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// End of the if ($result===false) statement</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// And now that last bit of HTML from the WordPress Theme</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Make sense? Let&#8217;s take a look at two lines in a bit more detail.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span><span style="color: #0000ff;">'&lt;link href=&quot;'</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/wp-content/plugins/WordTweet/WordTweet.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>get_bloginfo</strong> is a handy WordPress function which returns various useful pieces of information. For example, get_bloginfo(&#8216;template_directory&#8217;) returns, you&#8217;ve guessed it, the URL of the template directory.</p>
<p>With <strong>get_bloginfo(&#8216;url&#8217;)</strong> we are grabbing the blog URI which the user has set in <strong>Settings</strong>. We then just add in the path to the .css file, which we know is in the WordTweet directory.</p>
<p>Secondly,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;@&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iTweets</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweets'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>So, <strong>(substr($message,0,1)</strong> is a way of grabbing a sub-string (part of a string) from our string <strong>$message</strong>. We are interested in the first character, because I want to know if it&#8217;s a &#8216;@&#8217;, so we add to parameters &#8217;0,1&#8242; The first parameter tells PHP where to start, and we start with the first character which is in position &#8217;0&#8242;. The second parameter is how many characters we want, in our case just the &#8217;1&#8242;.</p>
<p>We then check to see if this is NOT equal to &#8216;@&#8217; with <strong>!=</strong>. If it&#8217;s NOT &#8216;@&#8217; then it&#8217;s not a Twitter reply and so we can display this Tweet. But we have one more check to make!</p>
<p>The second part of that If statement checks to make sure we are only displaying the number of Tweets the user specified. Initially this was just set as <strong>$options['tweets']</strong>, but I had to change it to <strong>+1</strong>. Why? Because I&#8217;m not displaying the first Tweet (it appears in the header of my site) I need to start on Tweet 1, not Tweet 0 (the first in our array). Which means if I want to display 5 Tweets I actually have to loop through until 5 (rather than 4 &#8211; remember 0 to 4 is FIVE Tweets).</p>
<p>I hope that makes sense, as it&#8217;s rather convoluted. If your blog doesn&#8217;t display Tweets anywhere else, you can remove the <strong>&#038;&#038; ($iTweets < $options['tweets']+1))</strong> bit.</p>
<p>Right, that&#8217;s it for part 2. Part three will finish things off with the options and look at the css. It&#8217;s in the css that we add the Twitter logo. I&#8217;ll also suggest some further reading, and ways you can develop this simple script further.</p>
<p><a href="http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-1-of-3/">Go to part 1</a> | <a href="http://www.richardshepherd.com/how-to-write-a-wordpress-twitter-widget-part-3-of-3/">Go to part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-2-of-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to write a WordPress Twitter Widget &#8211; Part 1 of 3</title>
		<link>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-1-of-3/</link>
		<comments>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-1-of-3/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 07:57:44 +0000</pubDate>
		<dc:creator>richardshepherd</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.growlingranger.com/?p=352</guid>
		<description><![CDATA[So you may have noticed in the sidebar over there on the right there&#8217;s a bunch of my recent Tweets. There are plenty of WordPress Twitter widgets, some better than others, but why not start and write your own? In this three part tutorial we&#8217;ll look at putting together the basic code, and then in [...]]]></description>
			<content:encoded><![CDATA[<p>So you may have noticed in the sidebar over there on the right there&#8217;s a bunch of my recent Tweets. There are plenty of WordPress Twitter widgets, some better than others, but why not start and write your own? In this three part tutorial we&#8217;ll look at putting together the basic code, and then in further episodes we&#8217;ll start getting a little more advanced with some jQuery scripting.</p>
<p>First things first, make sure you read and understand the <a href="http://www.richardshepherd.com/how-to-create-a-wordpress-widget/">How to Create a WordPress Widget Tutorial</a>, as we&#8217;ll be building on that code. In fact, adding in the Twitter code is reasonably straightforward.</p>
<p>Twitter has a API we can use to grab all the details, but our life get easy if we use a prewritten PHP class that does some of the hard work for us. A couple are kicking around out there, but I&#8217;m going to work with the lightweight <a href="http://twitter.slawcup.com/twitter.class.phps">twitterPHP by David Billingham</a>. It doesn&#8217;t include all the functionality of the Twitter API, but it&#8217;s got everything we need to kick off with.</p>
<p><span id="more-352"></span></p>
<p>So, we know how to create a Widget thanks to our earlier tutorial. What we now need to do is:</p>
<ol>
<li>Start with the usual widget code</li>
<li>Send a call off to Twitter with our username and password</li>
<li>Ask Twitter for a certain number of Tweets</li>
<li>Display these Tweets in our widget</li>
<li>Finish up the widget code</li>
<li>Write the code for the WordPress widget options</li>
</ol>
<p>And that&#8217;s it. So, without further ado, I give you WordTweet &#8211; my WordPress Twitter widget!</p>
<h3>WordTweet</h3>
<p>Our code starts off almost identical to the WordPress widget tutorial:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: WordTweet
Plugin URI: http://www.richardshepherd.com
Description: A  widget that displays your Twitter Tweets
Author: Richard Shepherd
Version: v0.2
Author URI: http://www.richardshepherd.com
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> widget_WordTweet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// First we grab the Wordpress theme args, which we</span>
	<span style="color: #666666; font-style: italic;">// use to display the widget</span>
	<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// We also need to make sure we include the Twitter Library</span>
    <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'twitter.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Now we sniff around to see if there are</span>
	<span style="color: #666666; font-style: italic;">// any preset options</span>
	<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;widget_WordTweet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// If no options have been set, we need to set them</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$options</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	  	<span style="color: #0000ff;">'WordTweetTitle'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'WordTweet'</span><span style="color: #339933;">,</span>
	  	<span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span>
	  	<span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'tweets'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span>
	  	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Display the widget!</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'WordTweetTitle'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span></pre></div></div>

<p>You&#8217;ll spot a couple of changes. First we include the PHP Twitter class, which we will make sure is in the same directory as the widget.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'twitter.class.php'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Secondly we have changed our options code a little bit, to take into account the new options we need.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #666666; font-style: italic;">// If no options have been set, we need to set them</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$options</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	  	<span style="color: #0000ff;">'WordTweetTitle'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'WordTweet'</span><span style="color: #339933;">,</span>
	  	<span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span>
	  	<span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'tweets'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span>
	  	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next up we use the Twitter class to get our Twitter feed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">// Create a new Twitter object and query for direct messages</span>
    <span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> twitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$t</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$t</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// This is where we grab the string as $result, from the users</span>
    <span style="color: #666666; font-style: italic;">// timeline, with a $count=1 so we only get the most recent</span>
    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$t</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">userTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweets'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So, we create an object <strong>$t</strong> and tell it our username and password which we grabbed from the options a few lines earlier. This is all happening on the server so it&#8217;s relatively secure &#8211; no one will see this info in our sourcecode.</p>
<p>Okay, then we query Twitter with the following options:</p>
<ol>
<li><strong>userTimeline</strong> &#8211; the timeline for the user specified in <strong>$options['username']</strong></li>
<li><strong>$id=false</strong> &#8211; This is optional, and allows us to return the results to the Twitter username or id specified. We don&#8217;t use this option, and hence set it to false.</li>
<li><strong>$count = ($options[&#8216;tweets&#8217; * 4)</strong> &#8211; Stick with me on this on, as the logic is a little convoluted. <strong>$count</strong> is simply the number of Tweets to grab. Now on my homepage I display the three most recent, so you might ask why we don&#8217;t simply put <strong>$count = 3</strong>. Good question! Well, as we&#8217;ll see in the next part of this tutorial I like to remove all my &#8216;@&#8217; Tweets because they are normally directed at just one persona and so not always suitable for my homepage. However, it&#8217;s impossible to know how many &#8216;@&#8217; Tweets there are in any given query until we&#8217;ve actually made the query. Make sense? It might be that my last five Tweets are all good. But it might be that four of them are &#8216;@&#8217; Tweets and so that would only leave me one to display. So, I grab four times the number of Tweets I want, because I&#8217;m pretty sure that if I want to display three Tweets, if I get the last 12 there are probably at least three non &#8216;@&#8217; Tweets in there. Why four times? Why not! It could be <strong>* 5</strong> or <strong>* 10</strong> if you wanted. For me, I&#8217;m happy that <strong>* 4</strong> is enough, although we can also set this as an option if we want.</li>
<li>Finally, we have <strong>$since = false</strong>. We can put a HTTP formatted date in here and that means we&#8217;ll only grab Tweets after that date. For this tutorial we are going to leave that as false, but you might want to introduce a new option to set this to the last day, or the last week.</li>
</ol>
<p>That&#8217;s enough for part one. Make sure you understand what we&#8217;ve done here, and also look through the twitter.class.php and make sense of what David Billingham has done.</p>
<p>In part two of this tutorial we&#8217;ll cycle through our Tweets and display them in our widget. See you then!</p>
<p><a href="http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-2-of-3/">Go to part 2</a> | <a href="http://www.richardshepherd.com/how-to-write-a-wordpress-twitter-widget-part-3-of-3/">Go to part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardshepherd.com/write-a-wordpress-twitter-widget-part-1-of-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
