Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#8734 closed enhancement (invalid)

Call Sidebars by Static Name, Not Dynamic Number

Reported by: dcole07's profile dcole07 Owned by:
Milestone: Priority: high
Severity: normal Version:
Component: Themes Keywords: reporter-feedback dev-feedback
Focuses: 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)

#1 @DD32
15 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);

#2 @jacobsantos
15 years ago

  • Keywords needs-patch added

#3 @jacobsantos
15 years ago

  • Keywords needs-patch removed

#4 @DD32
15 years ago

  • Keywords reporter-feedback dev-feedback added

#5 @DD32
15 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.