Is there a way to call a dynamic sidebar by name rather than ID.
Something like this:
$postName = get_the_category();
dynamic_sidebar($postName->category_nicename . '_sidebar') ;
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou can either pass Name or ID of dynamic sidebar to dynamic_sidebar.
http://codex.wordpress.org/Function_Reference/dynamic_sidebar
I don't understand your code or what you have done there. From the first answer you commented that the usage in the link doesn't work. My question is, how have you registered your sidebar.
Here is how to properly register a sidebar using register_sidebar
taken from the codex.
<?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>' );
?>
You can either now use the name (Sidebar name) or id (unique-sidebar-id) to call the sidebar to be used
<?php if ( is_active_sidebar( 'Sidebar name' ) ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( 'Sidebar name' ); ?>
</ul>
<?php endif; ?>
or
<?php if ( is_active_sidebar( 'unique-sidebar-id' ) ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( 'unique-sidebar-id' ); ?>
</ul>
<?php endif; ?>
If this doesn't work, then you are going wrong somewhere, because this is how things are done in my theme and in the default wordpress themes