Support » Themes and Templates » Twenty-eleven sidebar issue

  • Resolved E-V-M

    (@e-v-m)


    Hello

    I’m using Twenty-eleven template on my latest wordpress site, and it has turned out to be a mistake πŸ™ I hope someone would come up with a solution for my problem.

    I need both one-column and sidebar pages for the site but it seems I can only have either-or with this theme. If I set the default template to one-column, I can’t have sidebar on any page, even after I set them to use sidebar-template. If I set default template to have sidebar, every page has one and I can’t get single-column pages.

    I’ve read many articles on the subject and tried different solution, yet none of them work. I’ve added “get-sidebar” code on the single.php and page.php and removed and added code on funtions.php but none of this has any effect.

    I’m running out of schedule thanks to this issue. Any suggestion would be greatly appreciated!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Adam Blodgett

    (@epymetheus)

    Hi EVM,

    What you need to do is develop a new page template for the 2011 theme. This isn’t an easy thing to do, since you may have to play around with the CSS for the pages as well, but at least this will get you started.

    It sounds like you’re somewhat familiar with opening WordPress theme files, so my suggestion would be to set the site to the default, then create a page without a sidebar. My way of approaching it would be to make a copy of the page.php file, then remove the <?php get_sidebar() ?> code. That’s a good start, but I suspect you’ll still be left with a space for the sidebar on page, and you’ll have to futz with the CSS in order to compensate for it. Here’s the link to the WordPress page template codex: http://codex.wordpress.org/Pages#Page_Templates You’ll want the section called ‘Creating Your Own Page Templates’.

    With a custom page template you can use the modified Body class in order to identify the page you want to update. In this case it would be something like, body.page-template-xxx where xxx is the name of your custom page. You can then use that to extend the width of the copy containing DIV, probably either Primary or Content.

    That should do what you’re looking for.

    Good luck!

    Michael

    (@alchymyth)

    If I set default template to have sidebar, every page has one and I can’t get single-column pages

    static pages have no sidebar by default – are you possibly talking about index and/or archive pages?

    Thread Starter E-V-M

    (@e-v-m)

    Alchymyth – I’m talking about regular static pages. You can set a default layout for Twenty Eleven under Appearance tab, but if I choose to have a sidebar it displays across the whole site. And if you don’t…well it seems there’s no easy way to get it visible anywhere.

    Adam – I’ll propably have to try this. Luckily I have experience editing files and working with css. I’m just very miffed it has to be this complicated. Most other themes I’ve used had no problem using both two- and one-column pages.

    Michael

    (@alchymyth)

    You can set a default layout for Twenty Eleven under Appearance tab, but if I choose to have a sidebar it displays across the whole site.

    I disagree – look into page.php of Twenty Eleven – there is no sidebar call;

    only the build-in page templates ‘Showcase’ and ‘Sidebar Template’ have a sidebar.

    so in theory (and praxis), you can have the index pages (posts page, archive etc) with sidebar (i.e. theme option ‘Content on left’ or ‘Contenton right’), but static pages without sidebar (must have ‘default template’ selected under page attributes).

    the other way round (theme option ‘one-column’, but static pages with sidebar) would be much more complicated …

    Thread Starter E-V-M

    (@e-v-m)

    the other way round (theme option ‘one-column’, but static pages with sidebar) would be much more complicated …

    Sadly, this is what I need. I have static pages that mostly need visible widget area, but also few that need the whole site width for their content.

    I disagree – look into page.php of Twenty Eleven – there is no sidebar call;

    only the build-in page templates ‘Showcase’ and ‘Sidebar Template’ have a sidebar.

    Actually you are right now when I checked my site again. If I have “Content on right” AND sidebar-template active the sidebar appears. Those pages that have just “default” chosen show no sidebar content, but they still bush content to the right and just show white space where the sidebar should be (damn!). If I choose “no-sidebar” as a default, sidebar won’t show anywhere, not even on the sidebar-template pages. I’m headdesking so much with this theme right now.

    Michael

    (@alchymyth)

    Those pages that have just “default” chosen show no sidebar content, but they still bush content to the right and just show white space where the sidebar should be

    this might (unforunately) be caused by some of your customisations to style.css so far, as in the default, these pages would be centered with appr the same content width as a page with sidebar.

    if you can post a link to your site, someone might be able to have a look.

    Thread Starter E-V-M

    (@e-v-m)

    this might (unforunately) be caused by some of your customisations to style.css

    That was the case, but I had to modify the css to make my widgets and content fit properly.

    However, I FIXED THIS! Well, my way is not propably the best and cleanest but it worked for this site. I set the default template to “content on right” and set sidebar-template to all desired pages. Then I modified the sidebar-page.php and give “primary” div and new name. This way I could modify the css for sidebar-pages without messing up other pages. I also commented out the “twentyeleven_body_classes” part from functions.php, which made pages with default template expand to the full width. Now my site looks like it should!

    Adam Blodgett

    (@epymetheus)

    Hey EVM,

    Well done! Way to stick with it until you got what you needed!

    I believe you can mark this thread ‘resolved’ now.

    Cheers,
    A.

    That is not the right way to fix the problem. What you need to do is remove the body class(es) that it adds to the page and since the other styles exist, I replace them with them. There is a body_class filter you can use to filter it out. In my case, I need .two-column and .left-sidebar on all but the contact page and .one-column added to the contact page so I will make a template for the contact page by copying page.php and renaming it to one-column.php, remove get_sidebar(), and add some new code after get_header():

    function one_column_body_class_switch( $wp_classes, $extra_classes ) {
    	// Classes to remove
    	$classes_to_remove = array( 'two-column', 'left-sidebar', 'right-sidebar' );
    	// array_diff() Returns the difference
    	$wp_classes = array_diff( $wp_classes, $classes_to_remove );
    	// Classes to add
    	$classes_to_add = array( 'one-column' );
    	// array_merge() merges all arrays to your new array
    	return array_merge( $wp_classes, $classes_to_add, ( array ) $extra_classes );
    }
    add_filter( 'body_class', 'one_column_body_class_switch', 10, 2 );

    Now I can change the template on each page I want to be one-column. I could also do the same in another page for right-column if I wanted that option.

    Ok, now you can mark this thread resolved! πŸ™‚

    Thread Starter E-V-M

    (@e-v-m)

    Thank you for leaving your solution! I haven’t tested that on my site yet, but it does look more sensible way to do it. I wasn’t really familiar with filters when I posted this problem πŸ™‚

    I was wrong, actually. That turned out not to work. Twentyeleven actually has it’s own filter that works much easier. Here’s the function I actually used to do what I wanted:

    add_filter( 'twentyeleven_layout_classes', 'one_column_classes', 10, 2 );
    // Overrides layout classes for pages using one-column template
    function one_column_classes( $classes, $current_layout ) {
    	$current_page_template = basename( get_page_template() );
    	if ( $current_page_template == 'one-column.php' ) {
    		$classes = array( 'one-column', 'content' );
    	}
    	return $classes;
    }

    I’m sure I will need this later, lol.

    Hi i am New to wordpress and would like to try this as nothing else has worked for me

    Here’s the function I actually used to do what I wanted:

    Where would i add this?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Robslyn88, if you want further support than that provided in this thread, you can create your own thread.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Twenty-eleven sidebar issue’ is closed to new replies.