Creating Multiple Sidebar in Wordpress

Here you’ll know how to create multiple sidebar from scratch.

In this example, I created 2 sidebars. One from left and the other one from right.

The first thing you’ll need to do is to register the names of the sidebar (It’s like declaring a variable). This part is very important when you want your sidebar widgets to work.

I named the sidebars leftSidebar and rightSidebar.


<?php
if (function_exists('register_sidebar'))
{

register_sidebar(
array(
'name' => 'leftSidebar',
'before_widget' => '<li id="%1$s">',
'after_widget' => '</li>',
'before_title' => '<h2">',
'after_title' => '</h2>'
)
);

register_sidebar(
array(
'name' => 'rigtSidebar',
'before_widget' => '<li id="%1$s" class="holder">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgetTitle">',
'after_title' => '</h2>'
)
);

}

?>

Then create a page for these sidebars.

I created left.php for left sidebar. The codes below shows dynamic sidebar meaning, you can put as many widget as you want.
And the code “dynamic_sidebar(‘leftSidebar’)” is used to identify the sidebar. So all the widget you add on “leftSidebar” will show in left.php.
<ul>
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('leftSidebar')): ?>
<li>Please add some widgets here.</li>
<?php endif; ?>
</ul>

Repeat these codes to right.php and change “dynamic_sidebar(‘leftSidebar’)” to “dynamic_sidebar(rightSidebar’)”.

And to call these sidebars or to show these to the page, simply use this code

for left Sidebar
<?php include (TEMPLATEPATH . '/left.php'); ?>
And for right Sidebar
<?php include (TEMPLATEPATH . '/right.php'); ?>
And that’s all, you’re done!

Reply


About the Author

Urico MondeloUrico Mondelo is a twenty-something web developer and photographer wannabe. :) Specializing in Web Design, he create clean, engaging and functional websites built lovingly with web standards.

He is an experienced interface designer with a passion for creating great web experiences. For him, design is not just a job. It’s his hobby. His lifestyle.


This site, that means all his designs and photos are under License.

That means that you can use his work, but only if you don't change it or publish under other name. If you're planning to use his work somewhere, contact him.

Recent Posts

Gallery

dsc_0273 dsc_0448 edi at the shore dsc_0219 dsc_0311 cy-inal03 Snake Island dsc_0365 Heaven's Fam