• Resolved hunnsdon

    (@hunnsdon)


    I have managed to edit single.php to allow a sidebar on single post pages,as here:

    I inserted..

    <?php get_sidebar(); ?>

    In a new line just above the footer code at the bottom of the file:

    <?php get_footer(); ?>

    .. and used a new functions file (called my_functions.php) with:

    add_filter( 'body_class', 'mh_remove_body_classes' , 50 );
    function mh_remove_body_classes() {
       remove_filter( 'body_class', 'twentyeleven_body_classes' );
    }

    All single post pages now appear with a sidebar as required, but when I use the default page template for the home page I get a 3/4 page with an empty sidebar column to the right.

    What I want is for all static pages to have a choice of full width or with sidebar. How do I do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • What you want to do is create a custom template for the page with sidebar using this method – http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    So you create a duplicate of page, add the comment required to make a page template as described in the link above and then add the sidebar to that template.

    When you create a page, you’ll see on the right hand side a toggle that allows you to choose between templates.

    Thread Starter hunnsdon

    (@hunnsdon)

    I tried this using page.php and the result is still the same. The home page still is 3/4 wide with the side bar blank space.

    Which page do I duplicate?

    page.php or single.php?

    I think I need a bit more in depth instruction, please.

    If you want to add a sidebar to one of your page, then you need to make a custom template (see link above).

    you’ll need to duplicate page.php, change it’s name to say page-withsidebar.php
    add the comment (see link above)
    then make the changes you want to that template and update your theme.

    the problem might be that your code is removing all body_classes which are used by the theme for various formatting, including the sidebar.

    you might need to correct the .singular body_class output more selectively only on single posts;

    example:

    add_filter('body_class', 'filter_single_post_body_class', 20, 2);
    function filter_single_post_body_class($wp_classes, $extra_classes) {
    if( is_single() ) :
          foreach($wp_classes as $key => $value) {
          if ($value == 'singular') unset($wp_classes[$key]);
          }
    endif;
    return array_merge($wp_classes, (array) $extra_classes);
    }

    also see my article

    Thread Starter hunnsdon

    (@hunnsdon)

    Thank you to both of you.

    We are almost there. alchymyth your code works. I have only one difficulty now, and that’s figuring out what is the CSS to make the static pages full width and not centered in Twenty eleven.

    How is this done?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Use a browser developer tool for these kinds of CSS exploratory queries.
    Google Chrome’s built-in developer tool allowed me to find the CSS responsible for controlling the width [screenshot] [screenshot].

    Thread Starter hunnsdon

    (@hunnsdon)

    Thank you Andrew

    I was aware of that. I had tried but failed despite several attempts. I should of explained more thoroughly.

    I have tried again, different day different results, hooray!

    Thank you all again, very much appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Twenty Eleven – Sidebar on single post pages’ is closed to new replies.