Sidebar

From WordPress Codex:

Builds the definition for a single sidebar and returns the ID. Call on “widgets_init” action.

<?php register_sidebar( $args ); ?>

<?php $args = array(
	'name'          => __( 'Sidebar name', 'theme_text_domain' ),
	'id'            => 'unique-sidebar-id',
	'description'   => '',
        'class'         => '',
	'before_widget' => '<li id="%1$s" class="widget %2$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2 class="widgettitle">',
	'after_title'   => '</h2>' ); ?>
args
(string/array) (optional) Builds Sidebar based off of ‘name’ and ‘id’ values.

Default: None
  • name – Sidebar name (default is localized ‘Sidebar’ and numeric ID).
  • id – Sidebar id – Must be all in lowercase, with no spaces (default is a numeric auto-incremented ID). If you do not set the idargument value, you will get E_USER_NOTICE messages in debug mode, starting with version 4.2.
  • description – Text description of what/where the sidebar is. Shown on widget management screen. (Since 2.9) (default: empty)
  • class – CSS class to assign to the Sidebar in the Appearance -> Widget admin page. This class will only appear in the source of the WordPress Widget admin page. It will not be included in the frontend of your website. Note: The value "sidebar" will be prepended to the class value. For example, a class of "tal" will result in a class value of "sidebar-tal". (default: empty).
  • before_widget – HTML to place before every widget(default: <li id="%1$s" class="widget %2$s">) Note: uses sprintf for variable substitution
  • after_widget – HTML to place after every widget (default: </li>\n).
  • before_title – HTML to place before every title (default: <h2 class="widgettitle">).
  • after_title – HTML to place after every title (default: </h2>\n).

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.

 


From WordPress Codex:

<?php dynamic_sidebar( $index ); ?>

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 should give this function the name or number of the sidebar you want to print. This function returns true on success and false on failure.

The return value should be used to determine whether to display a static sidebar. This ensures that your theme will look good even when the Widgets plug-in is not active.

If your sidebars were registered by number, they should be retrieved by number. If they had names when you registered them, use their names to retrieve them.

index(integer/string) (optional) Name or ID of dynamic sidebar.

Default: 1

Return Value

(boolean) 
True, if widget sidebar was found and called. False if not found or not called.
Examples:
<?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?>
	<ul id="sidebar">
		<?php dynamic_sidebar( 'left-sidebar' ); ?>
	</ul>
<?php endif; ?>
<ul id="sidebar">
	<?php dynamic_sidebar( 'right-sidebar' ); ?>
</ul>
<ul id="sidebar">
<?php if ( ! dynamic_sidebar() ) : ?>
	<li>{static sidebar item 1}</li>
	<li>{static sidebar item 2}</li>
<?php endif; ?>
</ul>