• I want to use 2 separate widget areas in the sidebar. The first function is called “Right Sidebar Orange” (for orange boxes) and the second “Right Sidebar Blue” (for blue boxes), so this is my code in the sidebar.php:

    <?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Right Sidebar ORANGE') ) ?>
    <?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Right Sidebar BLUE') ) : else : ?>
    Without Widgets
    <?php endif; ?>

    The wordpress admin should be able to use either both widget areas or just one of them if they prefer one color.
    Now, as you can see – with the above code they are able to use either BOTH areas or just the blue one. If they do not use the blue area, the no-widgets area will be displayed.

    What can I do to prevent that? I want the no-widget area to be displayed when – and only when – none of the two areas are used.

    When I try to put both areas in one if condition using the or-operator || it does not work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Arcance

    (@arcance)

    This does not work, esmi.

    With this code, wordpress recognizes only the first widget area (in this case the orange one) and the second area will be ignored, if the first is empty.

    Thread Starter Arcance

    (@arcance)

    Okay, a little update..

    Now I’m using this code:

    if (function_exists('dynamic_sidebar')) {
        dynamic_sidebar('Sidebar A');
        dynamic_sidebar('Sidebar B');
    } else {
        // No Widgets
    }

    It works fine for this cases:

    • Widgets in Sidebar A and Sidebar B
    • Widgets only in Sidebar A
    • Widgets only in Sidebar B

    But if no Sidebar has widgets, it does not display the “No Widgets” area of the else-term. I think it is because function_exists(‘dynamic_sidebar’) is always true.

    How can I fix it, so that it displays the “No Widgets” area if both Sidebars are empty?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘two widget areas in the sidebar’ is closed to new replies.