Opened 4 years ago

Closed 4 years ago

#8734 closed enhancement (invalid)

Call Sidebars by Static Name, Not Dynamic Number

Reported by: dcole07 Owned by:
Priority: high Milestone:
Component: Themes Version:
Severity: normal Keywords: reporter-feedback dev-feedback
Cc:

Description

When sidebars are call or referred to, it should be done by the (static) name given, not by the (dynamic) number when they get registered. If WordPress is going to stick with numbers, it should be like posts, where a (static) number is assigned for the life of the install. The problem with the current way, of referring to a sidebar by a number they get registered by WordPress, is that this number can change with the addition/subtraction of sidebars. That means the admin has to move and edit the widgets.

The widget arranger, as well as anything else that calls or references to Sidebars should use a static name for each sidebar, instead of a dynamic number.

Change History (5)

comment:1   DD324 years ago

So.. Sounds like you should pass in the Static name and static ID when creating the sidebar, So as to select which one you want to show, as well as being able to refer to it in CSS, as well as solving the widget arranger problems..

ie:

add_action('init', 'theme_sidebars');
function theme_sidebars() {
	register_sidebar(array(
					'name' => 'Left Posts sidebar',
					'id' => 'left-posts-sidebar',
					'before_widget' => '<div class="widget">',
					'after_widget' => '</div>'
					));
	register_sidebar(array(
					'name' => 'Left Home sidebar',
					'id' => 'left-home-sidebar',
					'before_widget' => '<div class="widget">',
					'after_widget' => '</div>'
					));
}

the code to call those looks like:

	$is_blog = ( is_home() || is_single() || is_archive() || is_attachment() );
	
	$sidebar = $is_blog ? 'left-posts-sidebar' : 'left-home-sidebar';
?>
	<div class="sidebar <?php echo $sidebar ?>" id="<?php echo $sidebar ?>">
	<?php
		dynamic_sidebar($sidebar);
  • Keywords needs-patch added
  • Keywords needs-patch removed

comment:4   DD324 years ago

  • Keywords reporter-feedback dev-feedback added

comment:5   DD324 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Set the ID on the sidebars, and call it by that instead.

Eg: dynamic_sidebar('sidebar-left');

Note: See TracTickets for help on using tickets.