How can I add some extra sidebar locations for widgets in a child theme. The difficulty I'm having is because the parent theme uses some pretty gnarly setup to define the current sidebars.
I would like to add a sidebar area to my site's header and another sidebar area to the home template.
The parent theme's functions.php file starts off with:
<?php
add_action( 'after_setup_theme', 'et_setup_theme' );
if ( ! function_exists( 'et_setup_theme' ) ){
function et_setup_theme(){
global $themename, $shortname;
$themename = "Chameleon";
$shortname = "chameleon";
require_once(TEMPLATEPATH . '/epanel/custom_functions.php');
require_once(TEMPLATEPATH . '/includes/functions/comments.php');
require_once(TEMPLATEPATH . '/includes/functions/sidebars.php');
load_theme_textdomain('Chameleon',get_template_directory().'/lang');
require_once(TEMPLATEPATH . '/epanel/options_chameleon.php');
require_once(TEMPLATEPATH . '/epanel/core_functions.php');
require_once(TEMPLATEPATH . '/epanel/post_thumbnails_chameleon.php');
include(TEMPLATEPATH . '/includes/widgets.php');
add_action( 'wp_enqueue_scripts', 'et_add_responsive_shortcodes_css', 11 );
add_action( 'pre_get_posts', 'et_home_posts_query' );
add_action( 'et_epanel_changing_options', 'et_delete_featured_ids_cache' );
add_action( 'delete_post', 'et_delete_featured_ids_cache' );
add_action( 'save_post', 'et_delete_featured_ids_cache' );
}
}
Where "require_once(TEMPLATEPATH . '/includes/functions/sidebars.php');" is the only reference to sidebars in this file.
So the sidebars.php file in the includes directory contains the following:
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div> <!-- end .widget -->',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'Footer',
'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</div> <!-- end .footer-widget -->',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'Homepage',
'before_widget' => '<div id="%1$s" class="main-widget %2$s">',
'after_widget' => '</div> <!-- end .main-widget -->',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
));
}
?>
There is a sidebar.php file in the theme's root directory that contains the following:
<div id="sidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
<?php endif; ?>
</div> <!-- end #sidebar -->
So, let's (for now) work with adding a new sidebar area to the home template... The home.php template (which I have a modified copy of in my child theme folder) contains the following references to sidebars:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage') ) : ?>
<?php endif; ?>
and just before the end of the code for this template...
<?php get_sidebar(); ?>
My themes folder directory structure appears as so:
mywebsiteroot > wp-content > themes > Chameleon > includes | home.php
mywebsiteroot > wp-content > themes > Chameleon > includes | functions.php
mywebsiteroot > wp-content > themes > Chameleon > includes | sidebar.php
mywebsiteroot > wp-content > themes > Chameleon > includes | style.css
mywebsiteroot > wp-content > themes > Chameleon > includes > functions > sidebar.php
mywebsiteroot > wp-content > themes > Chameleon > includes > css > other stylesheets...
mywebsiteroot > wp-content > themes > lppscustom | home.php
mywebsiteroot > wp-content > themes > lppscustom | header.php
mywebsiteroot > wp-content > themes > lppscustom | footer.php
mywebsiteroot > wp-content > themes > lppscustom | style.css
And... this is where I'm stuck. I know you can have your own custom functions.php and sidebar.php files in the child theme folder, but how do I structure them? Do I have to include all code from the parent theme's files? If so, how do I modify the code so any reference to sub-directories are relative? If not, how do I make it load the parent theme's function file and sidebar file as well as my custom ones?
Any help would be greatly appreciated.