
We have previously covered how to add a widgetized sidebar to your theme and how to develop widgets. It is also possible to create a theme with multiple sidebars that are widget enabled. Today we’ll be going over how to achieve this.
Creating multiple widget-enabled sidebars is very similar to creating a single sidebar. In fact, the only thing we need to change is the code in our functions.php, the code in our sidebar.php file stays the same. Previously we used register_sidebar() to register our sidebars. To create multiple sidebars, we’ll be using register_sidebars() (it’s plural, if you didn’t notice the difference). This function is similar to register_sidebar(), in that it accepts the same parameters, but it also accepts a count parameter and a name parameter. Let’s take a look at an example of this:
[php]if (function_exists(‘register_sidebars’)) {
register_sidebars(2, array(
‘name’ => ‘Sidebar %d’,
‘before_widget’ => ‘<li class="widget">’,
‘after_widget’ => ‘</li>’,
‘before_title’ => ‘<h3>’,
‘after_title’ => ‘</h3>’,
));
}[/php]
Where the first parameter is the number of sidebars you want. The name parameter goes with the other parameters (the name will be run through sprintf() and %d will be replace with a number).
This code will create two sidebars with the same markup parameters. If you instead want multiple sidebars with different markup, just use the register_sidebar() method multiple times (and add in a name parameter).




