register_sidebar [ WordPress Function ]
| Parameters: |
|
| Uses: |
|
| Returns: |
|
| Defined at: |
|
Builds the definition for a single sidebar and returns the ID.
The $args parameter takes either a string or an array with 'name' and 'id' contained in either usage. It will be noted that the values will be applied to all sidebars, so if creating more than one, it will be advised to allow for WordPress to create the defaults for you.
Example for string would be
'name=whatever;id=whatever1'
and for the array it would be
array(
'name' => 'whatever',
'id' => 'whatever1')
.
name - The name of the sidebar, which presumably the title which will be displayed. id - The unique identifier by which the sidebar will be called by. before_widget - The content that will prepended to the widgets when they are displayed. after_widget - The content that will be appended to the widgets when they are displayed. before_title - The content that will be prepended to the title when displayed. after_title - the content that will be appended to the title when displayed.
Content is assumed to be HTML and should be formatted as such, but doesn't have to be.
Source
<?php
function register_sidebar($args = array()) {
global $wp_registered_sidebars;
$i = count($wp_registered_sidebars) + 1;
$defaults = array(
'name' => sprintf(__('Sidebar %d'), $i ),
'id' => "sidebar-$i",
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => "</li>\n",
'before_title' => '<h2 class="widgettitle">',
'after_title' => "</h2>\n",
);
$sidebar = wp_parse_args( $args, $defaults );
$wp_registered_sidebars[$sidebar['id']] = $sidebar;
add_theme_support('widgets');
do_action( 'register_sidebar', $sidebar );
return $sidebar['id'];
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- register_sidebar - WordPress Codex
Description. Builds the definition for a single sidebar and returns the ID. Call on " widgets_init" action. Usage. <?php register_sidebar( $args ); ?> Default Usage ...
codex.wordpress.org - register_sidebars() - WordPress Codex
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 ...
codex.wordpress.org - WordPress and register_sidebar - WP Engineer
Jan 28, 2009 ... Everyone who is building WordPress Themes probably implement the widget function in their theme. Code for the widgets is in functions.php.
wpengineer.com - 3.0 - How do register_sidebar() and get_sidebar() work together ...
Aug 18, 2010 ... function starkers_widgets_init() { // Area 1, located at the top of the sidebar. register_sidebar( array( 'name' => __( 'Primary Widget Area', ...
wordpress.stackexchange.com
Kullanýcý Tartýþmalarý [ wordpress.org ]
- robertjakobson on "register_sidebar before_widget and after_widget output is wrong"
- onerandommoment on "Dynamic Sidebar & Conditions"
- LoneWolfPR on "Can't rename a new dynamic sidebar"
- Jonas Grumby on "Can't rename a new dynamic sidebar"
- LoneWolfPR on "Can't rename a new dynamic sidebar"
- sdelamorena on "Does not install widgets in sidebar."
- enzokovski on "Does not install widgets in sidebar."
- sdelamorena on "Does not install widgets in sidebar."
- enzokovski on "Does not install widgets in sidebar."
- jami1955 on "widgets/dynamic sidebar not showing"