《PHP實例:WordPress中用于創建以及獲取側邊欄的PHP函數講解》要點:
本文介紹了PHP實例:WordPress中用于創建以及獲取側邊欄的PHP函數講解,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰register_sidebar()(創建側邊欄)
建立一個側邊欄,用來放置小工具.這個函數使用的時候請放在一個函數里,掛載到 “widgets_init” 鉤子.
PHP實戰用法
PHP實戰
register_sidebar( $args );
PHP實戰參數
PHP實戰$args
PHP實戰(字符串 | 數組)(可選)要創建的側邊欄的參數.
PHP實戰默認值:
PHP實戰
$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>'
);
PHP實戰數組參數介紹:
PHP實戰例子
PHP實戰
register_sidebar( array(
'name' => __( '右邊的側邊欄' ),
'id' => 'sidebar-1',
'description' => __( '右側邊欄的小工具.' ),
'before_title' => '<h3 class="title">',
'after_title' => '</h3 class="title">',
));
PHP實戰其它
PHP實戰該函數位于:wp-includes/widgets.php
PHP實戰get_sidebar()(獲取側邊欄)
get_sidebar() 用來引入側邊欄模板.如果指定名稱則引入當前主題根目錄的 sidebar-{name}.php 文件,不指定則引入當前主題根目錄的 sidebar.php 文件,如果文件不存在則引入 wp-includes/theme-compat/sidebar.php 文件.
PHP實戰用法
PHP實戰
get_sidebar( $name );
PHP實戰參數
PHP實戰$name
PHP實戰(字符串)(可選)引入模板的名稱,如果指定則引入當前主題根目錄的 sidebar-{$name}.php 文件.
PHP實戰默認值:None
PHP實戰例子
PHP實戰下邊的代碼將引入當前主題根目錄的 sidebar.php 文件:
PHP實戰
<?php get_sidebar(); ?>
PHP實戰下邊的代碼將引入當前主題根目錄的 sidebar-left.php 文件:
PHP實戰
<?php get_sidebar( 'left' ); ?>
PHP實戰下邊的例子分別引入了左側邊欄(sidebar-left.php)和右側邊欄(sidebar-right.php):
PHP實戰
<?php get_header(); ?>
<?php get_sidebar( 'left' ); ?>
PHP實戰內容內容
PHP實戰
<?php get_sidebar( 'right' ); ?>
<?php get_footer(); ?>
PHP實戰其它
PHP實戰此函數位于:wp-includes/general-template.php
維易PHP培訓學院每天發布《PHP實例:WordPress中用于創建以及獲取側邊欄的PHP函數講解》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/7962.html