小編給大家分享一下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' => '<h3 class="widgettitle">', 'after_title' => '</h3>' );
數(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' => '<h4 class="title">', 'after_title' => '</h4 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中用于創(chuàng)建以及獲取側(cè)邊欄的PHP函數(shù)有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前文章:WordPress中用于創(chuàng)建以及獲取側(cè)邊欄的PHP函數(shù)有哪些-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article12/discdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站維護、品牌網(wǎng)站設(shè)計、電子商務(wù)、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容