wordpress中的自定义小部件区域

时间:2011-05-22 14:38:03

标签: wordpress

我在wordpress中修改主题,并希望有可能将小部件放在模板的页眉和页脚位置。不仅是双方。

有没有人有关于此的某些信息的示例或链接?

由于

2 个答案:

答案 0 :(得分:1)

在主题的functions.php注册窗口小部件中,就像通常使用register_sidebar()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' );

将小部件添加到主题中的适当位置:

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

答案 1 :(得分:0)

相关问题