2011-05-22 26 views
0

我在wordpress中修改主題,並希望有可能將小部件放置在模板中的頁眉和頁腳位置。不僅僅是雙方。wordpress中的自定義小部件區域

有沒有人有關於此的一些信息的例子或鏈接?

感謝

+0

詳細的博客:http://sforsuresh.in/wordpress-creating-custom-widget-area/ – 2017-07-06 12:53:56

回答

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

這是正確的 – 2011-05-22 16:27:21

相關問題