Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create own template including submenu instead of the regular sidebar in Twenty Eleven.

Although I manage to create and select my new template the page ends up with bad CSS.

Here is what i have done

  • Copy sidebar-page.php and named it submenu-page.php
  • Copy sidebar.php and named it sidebar-submenu.php

In submenu-page.php

Added new template name "Sidebar left menu template" and changed

<?php get_sidebar(); ?>

to

<?php get_sidebar('submenu'); ?>

In In sidebar-submenu.php

Replaced all code with Hello World-link.

Even tough Hello World appears correctly the link is uncklickable due the div #primary is all over the page.

For unknown reason the HTML-body gets both singular and two-columns as value in the class attribute. If I edit sidebar-page with get_sidebar('submenu') everything looks and works great.

How do I tell wordpress that my template (submenu-page.php) is two columns and not both single and two columns?

Thanks for your time!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

the layout is controlled by the .singular css class, which in turn is generated in functions.php depending on the template. in your child theme of Twenty Eleven (if you don't have a child theme, create one first) add this code to functions.php:

add_filter('body_class', 'wpse_28044_adjust_body_class', 20, 2);  
function wpse_28044_adjust_body_class($wp_classes, $extra_classes) { 

if( is_page_template('submenu-page.php') ) : 
// Filter the body classes     

          foreach($wp_classes as $key => $value) {
          if ($value == 'singular') unset($wp_classes[$key]);
          }

endif; 
// Add the extra classes back untouched
return array_merge($wp_classes, (array) $extra_classes ); 
}

if you want to make the change in Twenty Eleven directly, edit functions.php, near the bottom (code shown after the edit):

if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) && ! is_page_template( 'submenu-page.php' ) )
share|improve this answer
    
Big thanks I will try this when I get home. –  Andersson Sep 9 '11 at 10:19
    
The second solution works great. I'm not able to copy functions.php to my child theme (ERROR 500). Is it safe to say the singular is default, I have to specify when not to use singular? Thanks! –  Andersson Sep 9 '11 at 20:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.