Function Reference/register sidebars

来自WordPress中文文档
跳转至: 导航搜索

wordpress.org.cn

Description

Creates multiple Sidebars.

Registers one or more sidebars to be used in the current theme. Most themes have only one sidebar. For this reason, the number parameter is optional and defaults to one.

The args array parameter can contain a 'name' which will be prepended to the sidebar number if there is more than one sidebar. If no name is specified, 'Sidebar' is used.

Usage

%%% <?php register_sidebars( $number, $args ); ?> %%%

Default Usage

<?php $args = array(
	'name'          => sprintf(__('Sidebar %d'), $i ),
	'id'            => "sidebar-$i",
	'description'   => '',
	'class'         => '',
	'before_widget' => '<li id="%1$s" class="widget %2$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2 class="widgettitle">',
	'after_title'   => '</h2>' ); ?>

Parameters

ttnumber/tt
(integer) (optional) Number of sidebars to create.
Default: 1noinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

ttargs/tt
(string/array) (optional) Builds Sidebar based off of 'name' and 'id' values.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

  • name - Sidebar name. (Note: If copying from default usage above, remove sprintf( ) wrapper function.)
  • id - Sidebar id. (Note: "-$i" is added automatically to supplied 'id' value after the first; e.g., "Sidebar", "Sidebar-2", "Sidebar-3", etc.)
  • description - Text description of what/where the sidebar is. Shown on widget management screen. (Since 2.9) (default: empty)
  • class - CSS class name to assign to the widget HTML (default: empty).
  • before_widget - HTML to place before every widget.
  • after_widget - HTML to place after every widget.
  • before_title - HTML to place before every title.
  • after_title - HTML to place after every title.

The optional args parameter is an associative array that will be passed as a first argument to every active widget callback. (If a string is passed instead of an array, it will be passed through parse_str() to generate an associative array.) The basic use for these arguments is to pass theme-specific HTML tags to wrap the widget and its title.

Return Values

None.

Example

This will register 1 sidebar named Sidebar:

register_sidebars();

This will create 2 sidebars named “Foobar 1″ and “Foobar 2″:

register_sidebars(2, array('name'=>'Foobar %d'));

This will create 2 sidebars with <h1> and </h1> before and after the title:

register_sidebars(2, array('before_title'=>'<h1>','after_title'=>'</h1>'));

Changelog

Since: 2.2.0

Source File

register_sidebars() is located in onlyincludecodewp-includes/widgets.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.

Parameters

  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.

Usage

Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre

/div

wordpress.org.cn.

Related

模板:Sidebar Tags

includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude