About Blogging WP Tutorials Google Apple Computers Downloads SEO Facebook Twitter
  • 27/11/2007    

How to Create Multiple Dynamic Sidebars for WordPress Widgets

Advertisements

In the last tutorial, you learnt how to widgetize your wordpress theme to support wordpress widgets. Now this tutorial explains how to create multiple dynamic sidebars to add various combinations of widgets to customize your wordpress theme even more.

I suggest you read how to Widget-Enable WordPress Themes in 3 Easy Steps before reading further as examples will be quoted in the same context.

Edit Functions.php for Multiple Dynamic Sidebars

The functions.php code which helped to widgetize your wordpress theme and support a single dynamic sidebar, now needs to be edited (using any text editor like Notepad) to support multiple sidebars. You remember we had modified the default function.php from

<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>

to the new code below to support our customized template with h4 subtitles and non-default unordered lists in the sidebar. REMEMBER you need to edit functions.php to match your wordpress theme or it will not work.

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

To support multiple sidebars, I simply need to specify that multiple sidebars be used and name them as I like. In our case I use Sidebar1, Sidebar2 etc and as many as you like. The code now looks like this -

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

I personally have extended this capacity to 6 dynamic sidebars on this blog. Here is how it looks like on top of admin panel.

4 Dynamic Widget Sidebars
Now you can drag and drop widgets of your choice to different sidebars and customize the options. Remember to Save Changes or else all customization is lost.

Add Dynamic Sidebars to WordPress Template

Now you need to place the code in the wordpress theme template where you want the relevant wordpress widgets to work. Instead of the previous code, you can place the different dynamic sidebars in different areas of the template.

Sidebar1 code goes like this
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>

Sidebar2 code goes like this
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>

Save the template and watch your widgets go live. You can add lots of dynamic sidebars with various widget combinations and have truly unique web design concept.

68 Responses

  1. The dynamic sidebar template codes have to be inserted into the sidebar.php in your blog template. Otherwise how will it know where the code has to be executed. :-)

    QuickOnlineTips posted on 06/04/2008
  2. Great tutorial, thanks, I was looking for something like this !

    jbj posted on 05/07/2008
  3. As an amateur PHP programmer struggling to get my own site developed, I found this article to be of great assistance. Without this I would still have been struggling to figure this lot out. Thanks.

    sailor posted on 06/07/2008
  4. Hi!

    I found this article to be incredibly helpful, however, I’m having trouble with the headers in my second sidebar (which is actually at the very bottom of the page). You can see the “Calendar” but the title does not style with the like it should. The titles in the right sidebar are correct. I’m using for the titles and I’ve confirmed that my functions.php calls for . Can you assist?

    Thanks!

    Web-Betty posted on 28/08/2008
  5. I have got my dynamic sidebars widgetized in no time. Thanks alot! :)

    nasirJumani posted on 08/09/2008

Leave a Reply to “How to Create Multiple Dynamic Sidebars for WordPress Widgets”

Name Email Site