different sidebars for different page types
-
I am trying to have different sidebars for different page types on my underscores theme.
I want one sidebar for the index page (which is actually a static page), a different one for every “page”, and a third for all individual posts. So, three sidebars.I’ve registered these sidebars in my functions.php, like so:
register_sidebar( array( 'name' => __( 'Page-Sidebar', 'house-magic' ), 'id' => 'sidebar-page', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>', ) );
I also registered a sidebar-index. With this, they appear in my widgets panel.
I want to edit my sidebar.php code, so it will switch sidebars depending on page type (index, page, or post). I’ve tried this:
<?php if (is_page()) { $no_sidebar = !dynamic_sidebar('sidebar-page'); } else { $no_sidebar = !dynamic_sidebar('sidebar-1'); }
But it doesn’t work. I know I need another nested if statement to get it work for the index, but it’s not working at all as it is. When I test this sidebar code all the sidebars disappear.
I’ve also tried just editing page.php to call ‘sidebar-page’, but that doesn’t work either.
Any ideas of how I can do this?
Thanks a lot!
My site is house-magic.net
- The topic ‘different sidebars for different page types’ is closed to new replies.