开发者

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


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; ?>


Found this guide, said it all

http://www.studiograsshopper.ch/code-snippets/how-to-add-a-widgetised-area-in-a-wordpress-theme/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜