dynamic_sidebar [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Display dynamic sidebar.
By default it displays the default sidebar or 'sidebar-1'. The 'sidebar-1' is not named by the theme, the actual name is '1', but 'sidebar-' is added to the registered sidebars for the name. If you named your sidebar 'after-post', then the parameter $index will still be 'after-post', but the lookup will be for 'sidebar-after-post'.
It is confusing for the $index parameter, but just know that it should just work. When you register the sidebar in the theme, you will use the same name for this function or "Pay no heed to the man behind the curtain." Just accept it as an oddity of WordPress sidebar register and display.
Source
<?php
function dynamic_sidebar($index = 1) {
global $wp_registered_sidebars, $wp_registered_widgets;
if ( is_int($index) ) {
$index = "sidebar-$index";
} else {
$index = sanitize_title($index);
foreach ( (array) $wp_registered_sidebars as $key => $value ) {
if ( sanitize_title($value['name']) == $index ) {
$index = $key;
break;
}
}
}
$sidebars_widgets = wp_get_sidebars_widgets();
if ( empty( $sidebars_widgets ) )
return false;
if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
return false;
$sidebar = $wp_registered_sidebars[$index];
$did_one = false;
foreach ( (array) $sidebars_widgets[$index] as $id ) {
if ( !isset($wp_registered_widgets[$id]) ) continue;
$params = array_merge(
array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
(array) $wp_registered_widgets[$id]['params']
);
// Substitute HTML id and class attributes into before_widget
$classname_ = '';
foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
if ( is_string($cn) )
$classname_ .= '_' . $cn;
elseif ( is_object($cn) )
$classname_ .= '_' . get_class($cn);
}
$classname_ = ltrim($classname_, '_');
$params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
$params = apply_filters( 'dynamic_sidebar_params', $params );
$callback = $wp_registered_widgets[$id]['callback'];
do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
if ( is_callable($callback) ) {
call_user_func_array($callback, $params);
$did_one = true;
}
}
return $did_one;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- dynamic_sidebar() - WordPress Codex
Description. This function calls each of the active widget callbacks in order, which prints the markup for the sidebar. If you have more than one sidebar, you ...
codex.wordpress.org - WordPress › Support » Tags — dynamic_sidebar()
(forgot?) Register · WordPress › Support » dynamic_sidebar() ...
wordpress.org - How to add a dynamic sidebar in Wordpress?
Mar 25, 2008 ... <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?> <?php endif; ?> [/raw]. Add the codes above, and make sure ...
www.balkhis.com - php - How to implement dynamic_sidebar( 'primary-widget-area ...
I am working on wordpress site.I am using by default sidebar.php of ... You practically wrote down your solution. just replace the <li> 's with <div> ...
stackoverflow.com
Gebruikersdiscussies [ wordpress.org ]
- rageboy on "function_exists('dynamic_sidebar') is false"
- rageboy on "function_exists('dynamic_sidebar') is false"
- onerandommoment on "Dynamic Sidebar & Conditions"
- roblagatta on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- Charlosa on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- roblagatta on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- Charlosa on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- Charlosa on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- Charlosa on "[Plugin: The Events Calendar] dynamic_sidebar hiding Gridview"
- apax27 on "Modify dynamic_sidebar for categories/subcategories"