Eric Herlitz
Eric Herlitz

Reputation: 26267

Custom widget area in wordpress

Im modifying a theme in wordpress and would like to have the possibility to place widgets in both the header and footer locations in the template. Not only the sides.

Does anyone have an example or link to some info regarding this?

Thanks

Upvotes: 0

Views: 1862

Answers (2)

Johannes P.
Johannes P.

Reputation: 4123

In your theme's functions.php register widgets as you normally would with register_sidebar() or register_sidebars:

function the_widgets_init() {
     $args = array(
         'name'          => sprintf(__('Sidebar %d'), $i ),
         'id'            => 'sidebar-$i',
         'description'   => '',
         'before_widget' => '<li id="%1$s" class="widget %2$s">',
         'after_widget'  => '</li>',
         'before_title'  => '<h2 class="widgettitle">',
         'after_title'   => '</h2>'
     );
     /* modify the above values as you deem suiting */
     if ( !function_exists('register_sidebars') )
          return;
          register_sidebars(3, $args);
     /* first argument (currently '3') is the amount of widgets you want */
}
add_action( 'init', 'the_widgets_init' );

Add the widgets in the appropriate places in your theme:

<?php if (function_exists('dynamic_sidebar')) : ?>
    <div id="header-sidebars">
        <div id="header-sidebar1">
            <?php dynamic_sidebar(1); ?>
        </div>
    </div>
    <div id="footer-sidebars">
        <div id="footer-sidebar1">
            <?php dynamic_sidebar(2); ?>
        </div>
        <div id="footer-sidebar2">
            <?php dynamic_sidebar(3); ?>
        </div>
   </div>
<?php endif; ?>

Upvotes: 1

Related Questions