Vikram Rao
Vikram Rao

Reputation: 1078

How to check multiple sidebars presence?

I am making a theme for my site which is WordPress based. I wanted a small help as I am not an expert on php. My issue is like this:

I have a side bar div which again within it has 4 sidebars:

 <div id="jp-double-bar" class="equal">
    <?php if ( is_active_sidebar( 'double-top' ) ) : ?>
    <div class="jp-double-top">
        <?php dynamic_sidebar( 'double-top' ); ?>
    </div>
    <?php endif; ?>
    <div class="double-middle">
        <?php if ( is_active_sidebar( 'middle-2' ) ) : ?>
        <div class="jp-middle-2 equalmiddle">
            <?php dynamic_sidebar( 'middle-2' ); ?>
        </div>
        <?php endif; ?>
        <?php if ( is_active_sidebar( 'middle-1' ) ) : ?>
        <div class="jp-middle-1 equalmiddle">
            <?php dynamic_sidebar( 'middle-1' ); ?>
        </div>
        <?php endif; ?>
    </div>
    <?php if ( is_active_sidebar( 'double-bottom' ) ) : ?>
    <div class="jp-double-bottom">
        <?php dynamic_sidebar( 'double-bottom' ); ?>
    </div>
    <?php endif; ?>
</div>

Here my issue is that if I do not publish any widgets in any of the sidebars, still the outer <div id="jp-double-bar"> shows up.

My question is....... The way we are wrapping for individual sidebar with an <?php if ():?> statement, is there a way to wrap the main outer div with 4 if statements.

Like if there is no widget published in any of the 4 sidebars then the main outer div should not display at all.

Kindly help.

Regards

Upvotes: 0

Views: 623

Answers (1)

mrtsherman
mrtsherman

Reputation: 39872

It seems that you have to be using the wp_get_sidebars api call to retrieve the bars. Check and see if this has a length of zero (empty).

Or just use and statements

if (is_active_sidebar( 'double-bottom' ) && is_active_sidebar('') && ...) {}

Upvotes: 1

Related Questions