欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WordPress中用于創(chuàng)建以及獲取側(cè)邊欄的PHP函數(shù)講解

 更新時間:2015年12月29日 14:35:50   作者:斌果  
這篇文章主要介紹了WordPress中用于創(chuàng)建以及獲取側(cè)邊欄的PHP函數(shù)講解,分別為register_sidebar()函數(shù)和get_sidebar()的使用,需要的朋友可以參考下

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

相關(guān)文章

最新評論