<?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>Jeff Combs - IT Professional / Web Developer &#187; Wordpress</title>
	<atom:link href="http://jcombs.net/category/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://jcombs.net</link>
	<description>System Administration</description>
	<lastBuildDate>Sat, 24 Dec 2011 17:56:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress Widgets</title>
		<link>http://jcombs.net/wordpress/wordpress-widgets</link>
		<comments>http://jcombs.net/wordpress/wordpress-widgets#comments</comments>
		<pubDate>Tue, 27 Oct 2009 01:19:58 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://jcombs.net/?p=57</guid>
		<description><![CDATA[WordPress widgets allow you to dynamically add content to sidebars directly from the wordpress control panel. I think this is a great option. The reason I&#8217;m using a Blog CMS is to reduce the amount of code I have to write, so this means less markup in my theme. I&#8217;m using only one sidebar on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://jcombs.net/wp-content/uploads/2009/10/wordpress.jpg" alt="wordpress" title="wordpress" width="221" height="225" class="alignright size-full wp-image-58" /></p>
<p>WordPress widgets allow you to dynamically add content to sidebars directly from the wordpress control panel.  I think this is a great option.  The reason I&#8217;m using a Blog CMS is to reduce the amount of code I have to write, so this means less markup in my theme.  I&#8217;m using only one sidebar on this site with a few widgets, including search, categories and links.  </p>
<p>There are a few tricks to get widgets to work how you want, but it is relatively quick and painless.  I&#8217;ll give an example of how I made this theme widget ready.</p>
<p><span id="more-57"></span></p>
<p>It starts in your functions.php file in your theme folder.  If you don&#8217;t have a functions.php file, you&#8217;ll have to create one.  You can define as many &#8220;sidebars&#8221; as you wish, but for this example I&#8217;m only using one.  My file looks like this:</p>
<pre class="brush: php">
&lt;?php

if ( function_exists(&#039;register_sidebar&#039;) ) {
	register_sidebar(array(
        &#039;name&#039; =&gt; &#039;sidebar&#039;,
        &#039;before_widget&#039; =&gt; &#039;&lt;div class=\&#039;widget %2$s\&#039;&gt;&#039;,
        &#039;after_widget&#039; =&gt; &#039;&lt;/div&gt;&#039;,
        &#039;before_title&#039; =&gt; &#039;&lt;h2&gt;&#039;,
        &#039;after_title&#039; =&gt; &#039;&lt;/h2&gt;&#039;
	));
}

?&gt;
</pre>
<p>Name is what you will see when you open your widgets section in the admin control panel.  Before_widget and after_widget allow you to wrap your widget with whatever tags you wish, in this case a div.   You&#8217;ll see that my div has a class of &#8216;widget %2$s.  This allows me to address my widgets in CSS.  Each widget will have the class &#8220;widget&#8221;.  They will also have a more specific class that lets me target that widget.  That is what %2$ is doing.  So for my search widget, I&#8217;ll have a class of &#8220;widget widget_search&#8221;.  Now I can target &#8220;widget_search&#8221; specifically in my CSS to create unique styles.  Before_title and after_title allow me to add custom tags for my title, in this case of a header h2.  </p>
<p>Now that the functions.php file has been created/modified, you should see it in your &#8220;Widgets&#8221; section under &#8220;Appearance&#8221; in the control panel.  You can simply drag any of the available widgets to the appropriate widget based on the same you gave it in your functions.php array.  </p>
<p>In your theme templates, you have to call the dynamic sidebar.  You can use some conditional logic to check if dynamic sidebars are set, but I know I&#8217;ll be using them, so I just call the method statically with the following code:</p>
<pre class="brush: php">
&lt;?php dynamic_sidebar(&#039;sidebar&#039;); ?&gt;
</pre>
<p>You can call this from anywhere, to make things easy, I&#8217;m calling it in sidebar.php.  This way I can keep my reference to <?php get_sidebar(); ?> that is already defined in my template files.  </p>
<p>Finally you&#8217;ll want to style your widgets in CSS.  I use a standard &#8220;.widget&#8221; definition and then use the custom classes to define my header images.  For example, in my categories widget looks like this:</p>
<pre class="brush: css">
.widget_categories h2 {
    background: url(images/categories.jpg) 0px 0px no-repeat;
}

.widget_categories ul li {
    width: 257px; height: 25px;
}

.widget_categories li a {
    background: url(images/categoriesli.jpg) no-repeat;
    padding: 0 0 0 35px;
    display: block;
    color: #eee;
    text-decoration: none;
}

.widget_categories li a:hover {
    background: url(images/categoriesli.jpg) 0 -25px no-repeat;
    color: #fff;
}
</pre>
<p>That defines my header and unordered list for the categories widget which is completely dynamic.  </p>
]]></content:encoded>
			<wfw:commentRss>http://jcombs.net/wordpress/wordpress-widgets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

