Viewing 7 replies - 1 through 7 (of 7 total)
  • you might need to add some code to functions.php of the child theme to remove the .singular body_class output;

    see my post:

    https://www.transformationpowertools.com/wordpress/twenty-eleven-new-page-template-with-sidebar-correction

    Thread Starter absNzyg

    (@absnzyg)

    Thanks for the help, alchymyth. Unfortunately, the code didn’t work for me. I am not sure if I am doing things right. I am very clueless about PHP btw. I created a functions.php file in the childtheme folder. And my code looks like this

    <?php
    /**
     *This is our functions.php file for a child theme
    */
    add_filter('body_class', 'adjust_body_class', 20, 2);
    function adjust_body_class($wp_classes, $extra_classes) {
    
    if( is_page_template('new-sidebar-page-template-file-name.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 );
    }
    ?>

    Also, I created the page anew from archives.php template. It still didn’t work. Thanks.

    my mistake – I did not check your template’s html structure ??

    you cannot just take any page template to use in your theme;

    the html structure and css classes must match the structure of your theme.

    for an ‘archives’ template for Twenty Eleven, see for example:
    https://pastebin.com/b0AK2uVt

    keep what you have added in functions.php.

    Thread Starter absNzyg

    (@absnzyg)

    Thanks so much for quick reply and sharing the template code. Sorry, but the suggestion didn’t work either. In fact, earlier I used the same archives.php code that you shared. I only removed the search box option. But just to be doubly sure I am using Twenty Eleven child theme. So this archives template should match the classes in the theme, isn’t it?

    And when I inspected the html elements it looks the “div id=content” is the culprit. That’s taking more width compared to what it does on the home page.

    Thread Starter absNzyg

    (@absnzyg)

    I think it looks like the “content” element of the erring page created from the archives.php template is taking the default margin of the Twenty Eleven theme rather than referring to the child theme.

    Yes, you are correct that the content is 100% width so that pushes the sidebar down. If the #primary div is used in other pages, you may want to only change the width in that page — so try this in your child theme style.css file:

    .page-id-79 #primary {
        width: 68%;
    }

    Thread Starter absNzyg

    (@absnzyg)

    Thanks WPyogi for replying. I found a solution on this page https://www.transformationpowertools.com/wordpress/twenty-eleven-sidebar-on-single-posts-and-pages

    So alchymyth once again thanks for running this useful website. In the code above I was using “adjust_body_class” instead that I used “blacklist_body_class”. I think that made the difference. Plus I added <?php get_sidebar(); ?> to page.php and single.php files in the theme. That was because I wanted side bar in the single post pages. Not sure if that had any impact on this issue. But anyway, thanks alchymyth. Keep up the good work.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Sidebar display issue with archives.php file’ is closed to new replies.