• Now, this is something that took me a while to learn myself. Today, I’ll be showing you how to create 2 seperate widget ready sidebars.

    First, you should already understand the basics of setting up a widget sidebar. In order to set up a widget sidebar, you need to components. You need your functions.php and your sidebar.php. Your functions.php should look like this:

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

    Your sidebar.php should look similar to this:

    <div class=’sidebar’>
    <?php if( function_exists(’dynamic_sidebar’) && dynamic_sidebar() ) : else : ?>
    STATIC SIDEBAR CONTENT
    <?php endif; ?>

    That will give you the basic single sidebar widget. Now, in order to create two sidebars, we need to make the functions.php a little more advanced. Replace your functions.php with

    <?php

    if (function_exists(’register_sidebar’))
    {
    register_sidebar(array(
    ‘name’ => ‘left_sidebar’
    ));

    register_sidebar(array(
    ‘name’ => right_sidebar’
    ));
    }

    ?>

    What this does is:

    • Declares if Sidebar widget is turned on
    • Creates an array, and declares left_sidebar
    • Creates an array, and declares right_sidebar

    sidebars

    Now, if you look at your Widgets Tab (In the wp-admin, under Presentation, Widgets) you should now have two dynamic sidebars. Each sidebar allows you to enter different widgets, on each sidebar. Now, this isn’t complete, you now need to change your sidebar code.

     

     

     

     

     

    Open up your Sidebar file(s), since you have two sidebars, you might want them seperate. Now, replace your <?php ?> function with this one,

    <?php
    if ( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar(’left_sidebar’) ) : else :
    ?>

    What this does is:

    • Checks to see if your dynamic_sidebar is turned on
    • Selects the sidebar, left_sidebar

    This will now display the left_sidebar. Simply copy that code, and replace left_sidebar with right_sidebar to display the right sidebar.

    Using this, you can have several widgetized sidebars!

     

     



    This entry was posted on Monday, April 7th, 2008 at 11:14 am and is filed under Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 0 Comments

    Take a look at some of the responses we've had to this article.

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message: