How to add multiple widget sidebars to your WordPress blog

March 1st, 2010 / 5 Comments » / by TSG

Our first ever guest post is by Anthony Hortin of Maddison Designs.
You can follow Anthony on Twitter @maddisondesigns

I’ve found that the term “sidebar” within WordPress can have multiple meanings. Within your index.php file you will most likely find a call to the php function get_sidebar(). This is referring to the sidebar column, sometimes called the right-hand (or left-hand) navigation column. A sidebar also refers to the location where you add all your Widgets. The Widgets control the content that appears within the sidebar (column) and will usually display lists such as your Recent Posts, Categories, Links or dozens of other items.

Since WordPress is so configurable, it’s possible to have multiple sidebar columns defined such as when you have multiple page templates set up. For example, you may have a specific page template defined for your sites static homepage. As well as defining the body content for that page, you can also define a separate sidebar in case you would like it to appear differently from the rest of the site.

It’s also possible to register multiple sidebars that contain all the widgets. This latter sidebar is what we’ll be discussing here. A typical WordPress theme may only have one sidebar configured although it’s not uncommon to have 2 or 3 or even more. Even though it’s called a “sidebar” it doesn’t need to specifically reside in the sidebar of your website. You can add a “sidebar” to anywhere in your site you want to display your widgets. A common place to include them is the site footer.

Defining your new sidebar

Adding additional sidebars to your site is relatively easy. Within your functions.php file you will most likely have something similar to the code below, for your existing sidebar.

<?php
if ( function_exists(‘register_sidebar’) ) {
register_sidebar(array(
‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</li>’,
‘before_title’ => ‘<h2 class=”widgettitle”>’,
‘after_title’ => ‘</h2>’
));
}
?>

To add another sidebar you simply need to register another instance. If you are registering more than one, then you will also need to name them. Change your functions.php file to look like the following. Take care to add in the extra line that specifies the name of your sidebar. Once these are functions are defined, you will notice the extra sidebar appear in the WordPress Dashboard under the Appearance > Widgets option. It’s here that you can drag and drop all your widgets into your various sidebars.

<?php
if ( function_exists(‘register_sidebar’) ) {
register_sidebar(array(
‘name’ => ’sidebar 1′,
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’
));

register_sidebar(array(
‘name’ => ‘footer sidebar 1′,
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’
));
}
?>

You can find more details on the various parameters of the above call on the WordPress Codex.

Adding your new sidebar to your template

Within your sidebar.php file, change the call to your existing sidebar to include its name that you defined within the functions.php file earlier.

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(’sidebar 1′) ) : ?>

<h2>Articles by month</h2>
<ul>
<?php wp_get_archives(‘title_li=&type=monthly’); ?>
</ul>

<h2>Categories</h2>
<ul>
<?php wp_list_categories(’show_count=0&title_li=’); ?>
</ul>

<?php endif; ?>

To add your new sidebar, you can either copy the above code or you can simply copy the following lines. Add these lines to wherever you’d like your new widgets to appear. In this example you can see from the name that I’m placing mine in the footer of my website. As before, don’t forget to specify the correct sidebar name. In the above code, the html that appears between the php statements is what will appear when there are no widgets added to your sidebar. This ‘default’ code can obviously be modified to suit your theme. In the following code, since there is no extra html, nothing will be displayed unless a widget has been added into the sidebar within your WordPress dashboard.

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘footer sidebar 1′) ) : ?>
<?php endif; ?>

You will now find that your site has two widgetized sidebars. As mentioned earlier, there’s no reason why you couldn’t include further ones. It’s simply a matter of registering the new sidebar and then including the php to display it, in the relevant part of your site template.

New Feature at TSG: Guest Posts

March 1st, 2010 / No Comments » / by TSG

Stay tuned because starting later today TSG will be posting our first guest post. We think this is a great feature – as the groups progress, people come up with great tips & tricks for the other group members. Well, we think those tip & tricks should be shared here. Our first tip is on Wordpress Theme Creation – Adding Multiple Widget Sidebars To Your Theme!

Connecting The Sidebar

February 23rd, 2010 / No Comments » / by TSG

Just to give a quick update, for tonight’s meeting we are supposed to have done ‘Connect With WordPress: The Sidebar’. See you at 7pm EST on Google Wave!

Tonight’s WordPress Theme Creation Study Group is canceled

February 16th, 2010 / No Comments » / by TSG

This weeks WordPress Theme Creation Study Group is canceled, we will move everything back a week. Here is the revised schedule:

02/23 – Connect With WordPress: The Sidebar
02/02 – Connect With WordPress: The Index File
03/09 – Connect With WordPress: The Functions File

See you on the 23rd!

WordPress Theme Creation Group Schedule

February 3rd, 2010 / No Comments » / by TSG

Great start with our new tutorial. Based on everyone’s input, we will be meeting next Tuesday at 7PM EST on Google Wave.

We are going to keep each session in line with the way the tutorial is broken out, so schedule will be as follows:

02/09 – Connect With WordPress: The Header/Footer
02/16 – Connect With WordPress: The Sidebar
02/23 – Connect With WordPress: The Index File
03/02 – Connect With WordPress: The Functions File

The tutorial continues to “Styling A Different Front Page” so I for one would be happy to continue on after The Functions File.

If anyone feels this should be broken out differently (it is moving too slow or too fast) just leave a comment and we’ll take a vote.

Here is the link to Creating Wordpress Themes 101: Connect To WordPress

Here are the links to the cheat sheets we discussed:
WordPress Cheat Sheet
The WordPress Help Sheet
The Advanced WordPress Help Sheet
WP Help Sheet

Reschedule meeting is tomorrow!

February 1st, 2010 / No Comments » / by TSG

Last weeks rescheduled meeting is tomorrow – see last post for details.

Chosen Tutorial: Creating WordPress Themes: Themes 101

January 20th, 2010 / No Comments » / by TSG

We have a winner – the new tutorial the group will be going with is Creating WordPress Themes: Themes 101 by BrassBlogs. Shelly has also agreed to stop into our second meeting to answer any questions! Next meeting will be Tuesday, January 26 @ Google Wave – 8PM (EST). Please look over the ‘Break Apart Your Files’ section for the meeting. We can discuss how to break up the tutorial at our meeting. As always, let me know if you have any questions.

WTC: New Tutorial Choices

January 6th, 2010 / 4 Comments » / by TSG

In case you missed the meeting last night, we decided the current tutorial we were using did not have enough detail, so we are choosing a new one to use. Below is a list of tutorials for us to choose from. Take some time to decide, and leave a comment for the one (or ones) you want to go with.

Here are the choices from the original group survey:
WordPress from scratch : Part 2
Premium Wordpress Theme Design Part 1 – The Photoshop Mock Up
How to write your own wordpress theme
Building Custom WordPress Theme
Dissection of a WordPress theme: Part 2
Stop Tweaking! Create Your Own Wordpress Theme

This is the one I mentioned during our meeting:
Creating WordPress Themes: Themes 101

Additional submitted tutorials:
Designing for Wordpress: Part One
Wordpress For Designers *more than one tutorial here
How to Code a WordPress Theme *more than one tutorial here
How I Learned To Build Wordpress Themes
How to Create a Wordpress Theme from Scratch

A recent addition:
WordPress Theme from Scratch – Day 3: HTML to WordPress

Tonight: Wordpress Theme Creation

January 5th, 2010 / No Comments » / by TSG

Reminder: Tonight the Wordpress Theme Creation Study Group is meeting at 8PM EST at Google Wave. If you are participating, and we do not yet have your Google Wave ID, please email or @ it to us on Twitter! See you tonight!

Welcome to TSG

January 4th, 2010 / No Comments » / by TSG

It took quite a while to find the time to create a functioning site for TSG. I’m lucky that work has been so busy – but that meant TSG kept getting pushed to the back burner. Well, with the new year upon us, I decided it was time. Even if I couldn’t have the custom created theme I wanted, I wasn’t going to let that hold up what I believe can be a valuable resource. I hope you agree!