<?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>Christian Schenk&#187; sidebar</title>
	<atom:link href="http://www.christianschenk.org/blog/tag/sidebar/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org</link>
	<description>Writing about my experiences with technology and all different kinds of projects and experiments</description>
	<lastBuildDate>Sun, 29 Aug 2010 09:08:16 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress: Adding a sidebar to your theme</title>
		<link>http://www.christianschenk.org/blog/wordpress-adding-sidebar-theme/</link>
		<comments>http://www.christianschenk.org/blog/wordpress-adding-sidebar-theme/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 07:40:19 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/?p=733</guid>
		<description><![CDATA[In another post I discussed the idea of placing a sidebar into your theme and using it to manage the navigation menu of your site. I came to the conclusion &#8211; proposed by other people from the WordPress community as well &#8211; that you can use a sidebar for basically anything but not just a [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="/blog/dynamic-navigation-menu-wordpress-theme/">another post</a> I discussed the idea of placing a <em>sidebar</em> into your theme and using it to manage the navigation menu of your site. I came to the conclusion &#8211; proposed by other people from the WordPress community as well &#8211; that you can use a sidebar for basically anything but not just a <em>sidebar</em>.</p>
<p>Although you can find this information in the <a href="http://codex.wordpress.org/">Codex</a> too, I would like to show you how easy it is to add a sidebar somewhere into your theme. You&#8217;ll see that it&#8217;s just about adding some function calls here and there &#8211; that&#8217;s it and you&#8217;ve got a new sidebar that can hold arbitrary widgets.</p>
<p><span id="more-733"></span></p>
<h2>Three simple steps</h2>
<p>Having a list of steps you can work through seems to be the best approach for this howto. Just follow these three steps and you&#8217;ll have a new sidebar in your theme.</p>
<h3>1. Register the sidebar</h3>
<p>First, you&#8217;ll have to register the new sidebar using <code>register_sidebar</code>. Open the file <code>functions.php</code> of your current theme &#8211; if there&#8217;s no such file just create it &#8211; and search for calls to <code>register_sidebar</code>. If you can&#8217;t find any that&#8217;s fine and you can go on inserting the function call where ever you like but if your theme already got a sidebar you should find at least one occurrence of the aforementioned function.</p>
<p>In case there&#8217;s already a call to <code>register_sidebar</code> insert the new calls to this function <em>after</em> the existing one. This way you&#8217;ll make sure that the widgets placed in another sidebar don&#8217;t suddenly appear in your new sidebar while the other one seems to be empty; has to do with the internal ordering of the sidebars.</p>
<p>The code is as easy as the following: just insert the function call and adjust the name as you see fit; please choose a unique name.</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;"># maybe other calls to register_sidebar here...
</span><span style="color: #666666; font-style: italic;"># ...
</span>register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My new sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># ...
</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Want to fine tune the appearance of your sidebar? Have a look at other parameters <a href="http://codex.wordpress.org/Function_Reference/register_sidebar">here</a>.</p>
<h3>2. Inserting the sidebar into the theme</h3>
<p>Once you&#8217;ve registered the sidebar you&#8217;ll have to tell WordPress where the widgets associated with the newly created sidebar should appear. This, of course, depends on your specific theme and other considerations as well.</p>
<p>For now, lets assume we wanted a new sidebar below the title of a post. We would open the file <code>single.php</code> &#8211; or <code>index.php</code> if <code>single.php</code> doesn&#8217;t exist &#8211; of our theme and insert the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">...
&lt;h1&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;/h1&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: #0000ff;">'My new sidebar'</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>
  &lt;!-- This will be displayed if the sidebar is empty --&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>

<p>See that we provide the name of the sidebar registered above in the function call to <code>dynamic_sidebar</code>. If you want to show some default content in case no widgets are assigned to the sidebar you can do so by changing the HTML comment to something else; this may be particularly interesting if you&#8217;re developing a theme and the user hasn&#8217;t customized the sidebar yet.</p>
<p>If you want to read more about <code>dynamic_sidebar</code> check out the Codex <a href="http://codex.wordpress.org/WordPress_Widgets_Api/dynamic_sidebar">here</a>.</p>
<h3>3. Adding widgets</h3>
<p>Now that you&#8217;ve added a new sidebar to your theme you should start adding widgets. Your new sidebar should appear under Appearance &#8211; Widgets and is ready to use. If you&#8217;re not satisfied with the appearance of the sidebar or the widgets try tweaking the parameters of <code>register_sidebar</code> or adjust your CSS.</p>
<h2>Conclusion</h2>
<p>It&#8217;s pretty easy adding multiple sidebars to your theme. This post presented the basics which are sufficient most of the time. If you want to learn more about sidebars and widgets a good starting point is the <a href="http://codex.wordpress.org/Widgets_API">Widgets API</a> page in the Codex; extra parameters can be found there.</p>
<p>The more sidebars a theme has the more flexible it is. From a user&#8217;s perspective it&#8217;s just nice to display widgets just where one wants to. Since it isn&#8217;t that hard to add another sidebar users can do this on their own or hire somebody to do this for them at low costs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/wordpress-adding-sidebar-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic menu for your WordPress theme</title>
		<link>http://www.christianschenk.org/blog/dynamic-navigation-menu-wordpress-theme/</link>
		<comments>http://www.christianschenk.org/blog/dynamic-navigation-menu-wordpress-theme/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 16:00:21 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/?p=284</guid>
		<description><![CDATA[Shows you how to add another sidebar to your theme that holds some Text widgets, each representing an item in your navigation menu.]]></description>
			<content:encoded><![CDATA[<p>I have <a title="Dynamic WordPress menu with animated JavaScript drop-downs" href="http://wordpress.org/support/topic/215815">found</a> <a title="Building a Dynamic WordPress Nav Menu" href="http://green-beast.com/blog/?p=157">various</a> descriptions about a dynamic navigation menu in a WordPress theme. What I&#8217;ve seen these solutions grab some pages and display the result either in the header or sidebar of the theme. It&#8217;s called <em>dynamic</em> because you can add pages to your blog and &#8211; depending on the implementation &#8211; a link to the appropriate page will appear in the menu.</p>
<p><span id="more-284"></span></p>
<p>Here&#8217;s my idea: What about adding another sidebar to your theme that holds some <code>Text</code> widgets, each representing an item in your menu? I think that&#8217;s ultra neat because you can:</p>
<ul>
<li>change your menu just by adding another <code>Text</code> widget</li>
<li>rearrange the order with drag and drop</li>
<li>use <a title="Widget Logic" href="http://wordpress.org/extend/plugins/widget-logic/">Widget Logic</a> to control where your menu items appear.</li>
</ul>
<p>Let&#8217;s implement this.</p>
<h2>Changing the theme</h2>
<p>Since I&#8217;m using a modified version of the great <a title="The Copyblogger Theme for WordPress" href="http://www.copyblogger.com/the-copyblogger-theme-for-wordpress/">Copyblogger Theme</a> I&#8217;ll show you how to change this specific theme. But it&#8217;s no problem to translate the following to other themes.</p>
<p>Basically we&#8217;ll have to change three files: <code>functions.php</code>, <code>sidebar.php</code> and <code>nav_menu.php</code>; I think the latter is a specialty of the Copyblogger theme. First we&#8217;ll register a new sidebar called <em>menu</em> in the file <code>functions.php</code> like so:</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;">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> <span style="color: #009900;">&#123;</span>
    register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>More likely than not you had a call to <code>register_sidebar</code> with no parameters: This registered your sidebar. As you can see we have to supply a name for each sidebar; make sure that each sidebar gets a unique name.</p>
<p>If your theme has got only one sidebar you have to change the file <code>sidebar.php</code> to pick up your original sidebar; if you already had more than one sidebar in your theme you can skip this step. Search for a call to <code>dynamic_sidebar</code> somewhere in the file <code>sidebar.php</code> and add the parameter <code>'sidebar'</code> to <code>dynamic_sidebar</code>:</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: #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: #0000ff;">'sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span></pre></div></div>

<p>This is a line from my file and it might look different in yours. Just make sure that the code uses the <em>right</em> sidebar here.</p>
<p>Finally the users of the Copyblogger theme will change the <code>nav_menu.php</code>. Everybody else may place the following in the <code>header.php</code> or wherever the menu of your theme might be.</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: #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: #0000ff;">'menu'</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>
&lt;li&gt;&lt;a href=&quot;/&quot;&gt;home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/archives/&quot;&gt;archives&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/about/&quot;&gt;about&lt;/a&gt;&lt;/li&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>

<p>This snippet will display the widgets associated with the sidebar called <em>menu</em>. If there&#8217;re no widgets in this specific sidebar the three hardcoded links will show up.</p>
<h2>Customizing the menu</h2>
<p>Now that you&#8217;ve got a new sidebar called <em>menu</em> go to <em>Design &#8211; Widgets</em> and under <em>Current Widgets</em> select the menu sidebar in the drop down list and click on <em>Show</em>. Add as many Text widgets as you like and use them to link to sensible pages on your website. It&#8217;s as easy as this.</p>
<p>Since we leverage the power of the cool widget screen you can easily rearrange the order of your menu items by dragging them around. You can add other widgets to your menu as well &#8211; maybe that makes sense too.</p>
<h2>Conclusion</h2>
<p>As we&#8217;ve seen the concept of the sidebar is powerful and can be used for different purposes: one of them is a neat navigation menu. The new menu is easy to setup in any theme and I bet you&#8217;ll really like the way to manage it via the widget screen.</p>
<p>If you&#8217;d like to read more about the functions from the <a title=" Widgets API" href="http://codex.wordpress.org/Plugins/WordPress_Widgets_Api">Widgets API</a> used in this post I recommend having a look at <a title="register_sidebar" href="http://codex.wordpress.org/WordPress_Widgets_Api/register_sidebar">this</a> and <a title="dynamic_sidebar" href="http://codex.wordpress.org/WordPress_Widgets_Api/dynamic_sidebar">that</a> page.</p>
<p>This was inspired by Justin Tadlock&#8217;s <a href="http://justintadlock.com/archives/2008/04/18/widgetize-this">Widgetize This</a> post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/dynamic-navigation-menu-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
