WordPress中用于創(chuàng)建以及獲取側(cè)邊欄的PHP函數(shù)講解
register_sidebar()(創(chuàng)建側(cè)邊欄)
建立一個側(cè)邊欄,用來放置小工具。這個函數(shù)使用的時候請放在一個函數(shù)里,掛載到 “widgets_init” 鉤子。
用法
register_sidebar( $args );
參數(shù)
$args
(字符串 | 數(shù)組)(可選)要創(chuàng)建的側(cè)邊欄的參數(shù)。
默認值:
$args = array( 'name' => __( 'Sidebar name', 'theme_text_domain' ), 'id' => 'unique-sidebar-id', 'description' => '', 'class' => '', 'before_widget' => '<li id="%1" class="widget %2">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' );
數(shù)組參數(shù)介紹:
- name:側(cè)邊欄名稱
- id:側(cè)邊欄 ID,必須為小寫,默認為遞增的數(shù)組 ID
- description:側(cè)邊欄描述
- class:給其中的小工具的額外 class
- before_widget:里邊的小工具的開頭 Html 代碼
- after_widget:里邊的小工具的末尾的 Html 代碼
- before_title:里邊的小工具的標(biāo)題的開頭 Html 代碼
- after_title:里邊的小工具的標(biāo)題的末尾的 Html 代碼
例子
register_sidebar( array( 'name' => __( '右邊的側(cè)邊欄' ), 'id' => 'sidebar-1', 'description' => __( '右側(cè)邊欄的小工具。' ), 'before_title' => '<h3 class="title">', 'after_title' => '</h3 class="title">', ));
其它
該函數(shù)位于:wp-includes/widgets.php
get_sidebar()(獲取側(cè)邊欄)
get_sidebar() 用來引入側(cè)邊欄模板。如果指定名稱則引入當(dāng)前主題根目錄的 sidebar-{name}.php 文件,不指定則引入當(dāng)前主題根目錄的 sidebar.php 文件,如果文件不存在則引入 wp-includes/theme-compat/sidebar.php 文件。
用法
get_sidebar( $name );
參數(shù)
$name
(字符串)(可選)引入模板的名稱,如果指定則引入當(dāng)前主題根目錄的 sidebar-{$name}.php 文件。
默認值:None
例子
下邊的代碼將引入當(dāng)前主題根目錄的 sidebar.php 文件:
<?php get_sidebar(); ?>
下邊的代碼將引入當(dāng)前主題根目錄的 sidebar-left.php 文件:
<?php get_sidebar( 'left' ); ?>
下邊的例子分別引入了左側(cè)邊欄(sidebar-left.php)和右側(cè)邊欄(sidebar-right.php):
<?php get_header(); ?> <?php get_sidebar( 'left' ); ?>
內(nèi)容內(nèi)容
<?php get_sidebar( 'right' ); ?> <?php get_footer(); ?>
其它
此函數(shù)位于:wp-includes/general-template.php
- 解析WordPress中控制用戶登陸和判斷用戶登陸的PHP函數(shù)
- 編寫PHP腳本清除WordPress頭部冗余代碼的方法講解
- WordPress主題制作中自定義頭部的相關(guān)PHP函數(shù)解析
- WordPress中調(diào)試縮略圖的相關(guān)PHP函數(shù)使用解析
- WordPress開發(fā)中自定義菜單的相關(guān)PHP函數(shù)使用簡介
- WordPress中用于獲取搜索表單的PHP函數(shù)使用解析
- 詳解WordPress中創(chuàng)建和添加過濾器的相關(guān)PHP函數(shù)
- 講解WordPress中用于獲取評論模板和搜索表單的PHP函數(shù)
- WordPress中編寫自定義存儲字段的相關(guān)PHP函數(shù)解析
- 詳解WordPress中用于更新和獲取用戶選項數(shù)據(jù)的PHP函數(shù)
相關(guān)文章
php顏色轉(zhuǎn)換函數(shù)hex-rgb(將十六進制格式轉(zhuǎn)成十進制格式)
將十六進制格式轉(zhuǎn)成十進制格式的函數(shù)代碼,也就是hex-rgb顏色轉(zhuǎn)換需要的2013-09-09