<?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>EM &#187; PHP</title>
	<atom:link href="http://www.ericm.ca/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ericm.ca</link>
	<description>Here lies random</description>
	<lastBuildDate>Sun, 31 Oct 2010 04:56:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using 2 or more different sidebars in WordPress</title>
		<link>http://www.ericm.ca/2008/01/03/using-2-different-sidebars-in-wordpress-my-first-php-code/</link>
		<comments>http://www.ericm.ca/2008/01/03/using-2-different-sidebars-in-wordpress-my-first-php-code/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 05:48:53 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sidebars]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ericm.ca/2008/web-development/using-2-different-sidebars-in-wordpress-my-first-php-code</guid>
		<description><![CDATA[I purchased a PHP book over 6 years ago and I only got through the first 20-30 pages before putting it down and letting it gather dust. After six long years, I finally faced a problem big enough for me to actually write a piece of code: How to display two or more different WordPress [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.ericm.ca%2F2008%2F01%2F03%2Fusing-2-different-sidebars-in-wordpress-my-first-php-code%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.ericm.ca%2F2008%2F01%2F03%2Fusing-2-different-sidebars-in-wordpress-my-first-php-code%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I purchased a PHP book over 6 years ago and I only got through the first 20-30 pages before putting it down and letting it gather dust. After six long years, I finally faced a problem big enough for me to actually write a piece of code:<br />
<em><br />
How to display two or more different WordPress sidebars (the column on the right) depending on the page a user is currently viewing?</em><span id="more-14"></span></p>
<h2>The Problem </h2>
<p>WordPress currently displays a single sidebar for all your templates (sidebar.php). My problem was that I wanted to use another sidebar (let&#8217;s call it sidebar2.php) as well. More specifically, I wanted this second sidebar to be displayed <em>only </em>on &#8216;<strong class="location">Single Post</strong>&#8216; (the template that displays the full blog post; the webpage you are viewing now). Then, the first sidebar would be displayed for all the other pages.</p>
<p>Being the newbie programmer I am, I tried using the <strong>original sidebar include code</strong> that WordPress uses to display the sidebar in your templates:</p>
<blockquote><p><strong class="code">&lt;?php get_sidebar(); ?&gt;</strong> </p></blockquote>
<p>And then modified it:</p>
<blockquote><p><strong class="code">&lt;?php get_sidebar<strong>2</strong>(); ?&gt;</strong></p></blockquote>
<p>Unfortunately, this did not work.</p>
<h2>The Solution</h2>
<p>Luckily, I stumbled upon this useful <a href="http://codex.wordpress.org/Conditional_Tags">page</a> at WordPress about &#8216;Conditional Tags,&#8217; specifically <a href="http://codex.wordpress.org/Conditional_Tags#Single_Post">this</a> section. </p>
<p>Basically, it tells us that &#8216;<strong class="location">Single Post</strong>,&#8217; the page you are currently viewing, is defined by WordPress as <strong class="code">&#8216;is_single()&#8217;</strong>. This is the page where I wanted to display the second sidebar. This also means that for every other page that was <em>not </em><strong class="code">&#8216;is_single()&#8217;</strong>, I would simply use the <em>original </em>sidebar include code to display the first sidebar as mentioned earlier.</p>
<p>Thus, a simple PHP <strong class="code">if and else</strong> conditional statement will do the trick. I replaced <strong class="code">&lt;?php get_sidebar(); ?&gt;</strong> from <strong class="location">header.php</strong> (or wherever this code is included in your template) with:</p>
<blockquote><p><strong class="code">&lt;?php<br />
if (is_single())<br />
include (TEMPLATEPATH . &#8216;/sidebar2.php&#8217;);<br />
else<br />
get_sidebar();<br />
?&gt;</strong></p>
<p><strong>Note:</strong> The above code assumes that you have created and uploaded a WordPress template called sidebar2.php</p></blockquote>
<p>In layman&#8217;s terms, <em>if</em> the current page you are viewing is &#8216;<em>Single Post</em>,&#8217; <em>then </em>the <em>second sidebar</em> will be displayed. <em>Else</em>, the <em>first sidebar</em> is displayed for all other pages. This piece of code can be adapted in many different ways including displaying more than 2 sidebars and displaying sidebars for specific templates.</p>
<p>I guess this is a rather simple fix, but after hours of Googling for a solution, I noticed that a lot of other WordPress users experienced this same problem.  Hopefully this article helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericm.ca/2008/01/03/using-2-different-sidebars-in-wordpress-my-first-php-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

