步驟一:在主題的functions.php中,添加一段代碼,開啟側邊欄功能,代碼如下:
<?php //參數 $args = array( 'name' => __( '主側邊欄'), 'id' => 'sidebar-01', 'description' => '將在網頁中顯示的側邊欄', 'class' => '', 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); //開啟側邊欄函數 register_sidebar( $args ); ?>
如果需要多個工具欄,再復制一個就可以了
步驟二:后台給側邊欄添加小工具
步驟三:在模版文件中調用側邊欄
<?php if ( is_active_sidebar( $index ) ) : ?> <?php dynamic_sidebar( $index ); ?> <?php else: ?> //提示用戶 //或者,顯示一些默認的邊欄效果 <?php endif; ?>
$index 指代哪個側邊欄,可以使用步驟一的name或id值識別
is_active_sidebar( $index )
判斷側邊欄是否被集合,如果激活了,返回true,否則返回false。
dynamic_sidebar( $index )
此函數的做用,是調用$index指定的側邊欄。
幫助文檔:
中文官方參考文檔:http://codex.wordpress.org/zh-cn:%E4%B8%BB%E9%A2%98%E7%89%B9%E6%80%A7
英文官方參考文檔:http://codex.wordpress.org/Theme_Features