Multiple Sidebars With Wordpress Widgets

Author: Stefan Vervoort | Please Comment!

As I am working on a new Wordpress theme I faced a problem with my sidebar and the widgets. This theme doesn’t run on one sidebar, but two. I didn’t know how to create more dynamic sidebars.

I asked Google, but there wasn’t a clear article that helped me along the way and I guess more people are struggling with this situation. After some research I finally found the solution on OrangeScale.

Widgets Core

To let Wordpress Widgets preform on your blog, you should have the functions.php file ready with the right codes. This widget codes in the functions.php file usually looks like this:

PHP

<?php

if ( function_exists('register_sidebar') )

register_sidebar();
?>

To give your Wordpress installation more sidebars, we have to extend these codes. We have to add more ‘options’ and we do that by adding more codes to the function and by given those seperated functions names like Sidebar 1 and Sidebar 2.

PHP

Sidebar 1

<?php

if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar 1',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));

Sidebar 2

<?php

if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar 2',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));

Name your Sidebar

To get more sidebars you need to name them and in our case, we will call them Sidebar 1, Sidebar 2 etc. as many as you would like. Here is how you do that:

PHP

You are able to change the values of before_widget, after_widget, before_title and after_title to whatever you like. These are just the example of what I use myself.

How to insert Multiple Widgets to your Theme

Open up the file you would like to have your widgets shown. When you already have one sidebar in place you will find the following codes:

PHP

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php } ?>
<?php endif; ?>

Now, find all the places you would like to add widgets. Insert Sidebar 1 where sidebar 1 should be located, and so on. Here we go:

PHP

Sidebar 1

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar 1') ) : ?>
<?php } ?>
<?php endif; ?>

Sidebar 2

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar 2') ) : ?>
<?php } ?>
<?php endif; ?>

Ready

After you’ve saved your file you will have two dynamic sidebars you are able to edit via Wordpress Widgets. Of course, al lot more sidebars can be created and all the creativity that follows next, that’s up to you. Do you want to style your widgets now?

Liked this post? Subscribe, or Share and Enjoy:
  • Digg
  • del.icio.us
  • Blogosphere News
  • Design Float
  • description
  • StumbleUpon

10 Comments. Add yours!

  1. Hosting
    10:58 pm on September 4th, 2008

    Thank you

  2. zacheos
    8:04 pm on September 9th, 2008

    Some people use a hierarchy method in the naming of the template files to achieve multiple WordPress sidebars, but in my opinion it is too cumbersome for most user’s needs. The method of multiple sidebars for WordPress that I use involves only a very simple PHP snippet added to the template to call the desired sidebar file depending on the area of the site that you are in.

  3. Stefan Vervoort
    9:13 pm on September 9th, 2008

    @ Zacheos - I appreciate your thoughts on this one. I’ve read your article, and I think that solution is great as well.

    The thing for me is, it doesn’t use widgets (which is possible to create of course), so for people using normal sidebars, your way is great.

    Thanks for your thoughts and I like the site you have there!

  4. stefano
    3:50 pm on October 18th, 2008

    it gave me error with }

  5. Jeffrey
    3:00 am on November 20th, 2008

    This is perfect, thank you for your help!

  6. dirty blue widgets
    2:59 pm on November 21st, 2008

    Thanks for the tutorial on adding multiple widgetst to the side bar. I’ve been trying to do this exact thing with little success on a few of my sites. This has helped improve my wordpress themes greatly.
    Thanks,
    Jason

Trackbacks

  1. WP Plugin Release - FV Code Highlighter » DivitoDesign - Webdesign Blog
  2. 5 maneiras de melhorar seu Template Wordpress | Wordpress Themes
  3. 5 Quick Ways To Enhance Your WordPress Theme - In the Woods
  4. stefanomavilio.com » Blog Archive » multiple sidebar, custom fields, feature, breadcrumb…what more?

leave a reply

This blog is a DoFollow blog. This means your URL counts as a backlink. Some basic HTML is allowed. Please keep all comments constructive, polite and on-topic. Any spam or offensive comments will be deleted.