Forums

how to wrap widgets inside a div, conditionally? (9 posts)

  1. multiplier
    Member
    Posted 2 weeks ago #

    At the bottom of my theme, I want to have a widgetized region that is wrapped in a div called "footer-widgets". But if there are no widgets activated, I don't want an empty div to show up.

    What I'm trying to accomplish is logic like this:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Widgets') ) : ?>
    <div id="footer-widgets"><!--widget stuff--></div>
    <?php endif; ?>

    What would be the right way to do this? Thanks!

  2. esmi
    Member
    Posted 2 weeks ago #

    Try:

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('Footer Widgets') ) : ?>
    <div id="footer-widgets"><!--widget stuff--></div>
    <?php endif; ?>
  3. multiplier
    Member
    Posted 2 weeks ago #

    That doesn't wrap all the widgets within the "footer-widgets" div, though. That's the main thing I'm trying to achieve.

  4. esmi
    Member
    Posted 2 weeks ago #

    Do they have to be wrapped in a single div or can they have individual divs?

  5. multiplier
    Member
    Posted 2 weeks ago #

    I want the entire widget region wrapped in one large div called "footer-widgets".

  6. esmi
    Member
    Posted 2 weeks ago #

    I think I've found it. Try:

    <?php if( is_dynamic_sidebar() ) ?><div id="footer-widgets">
    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('Footer Widgets') ) : ?>
    <!--widget stuff-->
    <?php endif; ?>
    <?php if( is_dynamic_sidebar() ) ?></div>

    http://codex.wordpress.org/WordPress_Widgets_Api/is_dynamic_sidebar

  7. multiplier
    Member
    Posted 2 weeks ago #

    Thanks, but unfortunately that still leaves an empty "footer-widgets" div if no widgets are activated.

    Any other ideas?

  8. wereallyloveyou
    Member
    Posted 2 weeks ago #

    This might help my question out too, thanks everyone! :)

    EDIT: Nevermind, it did not do anything either.

  9. multiplier
    Member
    Posted 2 weeks ago #

    Anyone else know how to write the conditional properly?

Reply

You must log in to post.

About this Topic

Tags