Viewing 6 replies - 1 through 6 (of 6 total)
  • In functions.php, if you’re already widgetized you’ll find this (if not add it):

    if ( function_exists('register_sidebar') )
    register_sidebar();

    To do multiple sidebars you’ll need this, too:

    if ( function_exists('register_sidebars') )
    register_sidebars(2);

    The (2) represents your 2 sidebars. If you want 3, put in 3, and so on.

    Now in your sidebar.php, we’re going to mess with the code a bit. Where you currently find:

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

    Replace with this:

    <?php if (is_home()) {
    if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else :
    } else {
    if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : } ?>
    //Put in stuff that'd show in case of no widgets
    <?php endif; ?>

    I’m sure there’s a cleaner way to do it, but…

    • dynamic_sidebar(1) will show on your home page and
    • dynamic_sidebar(2) will show on every other page

    At least it should. Haven’t tried it. Hope it works.

    Parse errors. Never mind me.

    Okay, do what I said in functions.php, but in your sidebar.php, but this instead:

    <?php if ( function_exists('dynamic_sidebar')):
    if (is_home()) dynamic_sidebar(1);
    else dynamic_sidebar(2);
    endif; ?>
    Thread Starter hopeworks

    (@hopeworks)

    I get two sidebars in widgets panel but no sidebars show up on site.

    here is the code (w/o your changes)

    <?php
    if ( function_exists('register_sidebar') )
    {
    register_sidebar(array('before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h2><em>',
    		'after_title' => '</em></h2>',
    		));
    }

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>

    Could someone explain me what is the meaning of this statement:

    <?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(1) ) : ?>

    That is a simple line of PHP which says this;

    IF the function “dydnamic_sidebar” doesn’t exist or running the function dynamic_sidebar(1) didn’t output anything then execute the following code until “else” or “endif”

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘2 different sidebars’ is closed to new replies.