开发者

Fixing sidebar overlap in twentyeleven

开发者 https://www.devze.com 2023-03-17 19:10 出处:网络
I\'m making a new page template with a sidebar in my child theme based on twentyeleven. It doesn\'t display properly due to this in twentyeleven\'s function.php:

I'm making a new page template with a sidebar in my child theme based on twentyeleven. It doesn't display properly due to this in twentyeleven's function.php:

function twentyeleven_body_classes( $classes ) {

if ( ! is_multi_author() ) {
    $classes[] = 'single-author';
}

if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
    $classes[] = 'singular';

return $classes;
}
add_filter( 'body_class', 'twentyeleven_body_classes' );

It adds the "singular" class to the body tag on any template other than the default sidebar-page.php, and this results in sidebar overlap.

I can't fix this using functions.php because the child theme functions.php is loaded BEFORE the parent theme one (so I can't just go through the $classes array and remove the "singular" element). I don't want to edit the parent's functions.php as this will be overwritten during updates, which defeats the entire point of using a child theme in the first place.

Any ideas?

EDIT: it seems I can get it to run after the parent's function.php using the after_setup_theme action hook.

Now I'm getting errors though.

My code is:

add_action( 'after_setup_theme', 'childtheme_override' );

function childtheme_override() {
    add_filter('body_class', 'twe开发者_JS百科ntyeleven_child_body_classes');
}

function twentyeleven_child_body_classes ($classes) {
    if ( is_page_template('container-sidebar-page.php') ) {
        foreach ($classes as $key => $value) {
        if ($value == 'singular') {
                 unset($classes[$key]);
                 $classes = array_values($classes);
            }
    }
    return $classes;
}


Figured it out: fixed by doing remove_filter and just copying the parent's body_classes and adding the template to the list that shouldn't have the "singular" class.

Errors are as follows:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\wamp\www\wp-content\themes\twentyeleven\inc\theme-options.php on line 40


Warning: join() [function.join]: Invalid arguments passed in C:\wamp\www\wp-includes\post-template.php on line 390
0

精彩评论

暂无评论...
验证码 换一张
取 消