• Hello, I am trying to make different page templates based on sidebar-page.php. I made an exact copy of it, changed the template name at the top, and assigned it as the template to a page. When I view it in my browser the sidebar drops down below the main content.

    I tried the fix here, but I don’t know exactly where to add the code specified, so I just added it to the very end of functions.php.

    Now when I load the page, I get this error:

    Fatal error: Cannot redeclare twentyeleven_excerpt_length() (previously declared in /home/bopjo/arrowriverbed.com/program/banjopicker/wp-content/themes/childtheme/functions.php:335) in /home/bopjo/arrowriverbed.com/program/banjopicker/wp-content/themes/twentyeleven/functions.php on line 337

    Can anyone help me with this? It is so frustrating! Why is it so hard to create new page templates with a sidebar? Shouldn’t this be easier to do out of the box, without the need for complex code to “fix” it? Sorry, I’m just really frustrated with it and have been struggling with it all day!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bopjo1

    (@bopjo1)

    Well I got the error to go away, but still have the original problem of the sidebar dropping down below the main content

    Here is the way it is supposed to look. This page uses sidebar-page.php as the template:

    LINK

    But here is how it ends up when I create a new template using sidebar-page.php. The sidebar drops below the main content:

    LINK

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your primary content has a width of 100%, therefore it spans the entire website and doesn’t make room for the secondary content (sidebar).

    Thread Starter bopjo1

    (@bopjo1)

    Yes, but WordPress is supposed to adjust that when using the sidebar-page.php template. I made an exact copy of that file, changed the template name at the top, and saved it as a different file name. When I assign it as a template to a page, I don’t get the same layout as the sidebar.php template.

    Thread Starter bopjo1

    (@bopjo1)

    Nevermind, I finally got it, but I would love to know why this is so hard to do? Surely people have the need for multiple static pages with different sidebars? Seems this should be much more convenient to achieve!

    https://codex.www.ads-software.com/Child_Themes#Using_functions.php

    don’t copy functions.php of the parent theme into the chilc theme;

    as for the sidebar page template, you need to add a filter function for the body_class into functions.php of the child theme, to remove the .singular class when using the sidebar page template;

    example:

    add_filter('body_class', 'adjust_body_class_for_template', 20, 2);
    function adjust_body_class_for_template($wp_classes, $extra_classes) { 
    
    if( is_page_template('yoursidebarpagetemplatefilename.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 );
    }

    EDIT PS:
    well done.

    I would love to know why this is so hard to do?

    it just is – ‘hard’ or ‘not hard’ depends on personal experience with WordPress; Twenty Eleven is just a bit tricky in some aspects.

    Thread Starter bopjo1

    (@bopjo1)

    Thanks. Yes, seems quite a bit more complex than twenty ten..

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sidebar-page.php issues’ is closed to new replies.