Sidebar hierarchy / help

I’m going round in circles here… :dizzy_face:

Can anyone explain the sidebar hierarchy?

OR

Is there a way of using “get_sidebar” instead of dynamic_sidebar when adding conditional statements to templates/sidebar.php?

sidebar hierarchy

CPT of “testimonials”

sidebar-archive-testimonials.php works for the archive page, but what file name should be used for single testimonial pages? Nothing I try works!

Also, on single pages, sidebar-pagename.php doesn’t work.
Nor does sidebar-page-pagename.php

Any help on this would be super!

get_sidebar

I’ve also tried fixing above issues by using conditional statements in templates/sidebar.php, but it seems I have to use dynamic_sidebar, not get_sidebar?

I don’t want a dynamic sidebar, I just want a normal one that uses the sidebar I create and tell it to use!

It seems like you’re trying to load a sidebar according to a template. The theme wrapper doesn’t affect the sidebar though, if you see here, it will always load templates/sidebar.php

https://github.com/roots/sage/blob/master/lib/wrapper.php#L17

Read the docs on how dynamic_sidebar works, but at the very least you should be able to put conditionals in templates/sidebar.php and load what you want. Alternatively you could put conditionals in the Wrapper class if you want to load different sidebar templates.

Hey Kalen,

Yeah I can get everything working using conditionals and dynamic_sidebar… but mu understanding of this was that dynamic_sidebar’s are registered as widget areas and used as such. I 'm not trying to create widgetized sidebars, just plain ol’fashioned sidebars!

Maybe I misunderstood. I’ll go back to the docs.

After staring at this for hours its suddenly dawned on me…

I dont have to use only “dynamic_sidebar” or “get_sidebar” in conditionals!

I can just use “get_template_part”! :tada:

<?php
if ( is_page('clients') ) :  
  get_template_part('templates/sidebar-why-choose');
elseif ( is_post_type_archive('testimonials') ) :
  get_template_part('templates/sidebar-why-choose');
else: 
  dynamic_sidebar('sidebar-primary');
endif;
?>
2 Likes