[wp-hackers] Child themes, and DB options

ravi ravi-lists at g8o.net
Thu Sep 17 16:47:04 UTC 2009


Hello all,

a few questions (following up on my previous one regarding extending  
themes):

If I understand it correctly, a child theme inherits template files  
from its parents (unless it has its own versions of those files). When  
such access happens, I assume include()s from the original/parent  
template of other parent PHP files will continue to work since the  
cwd() of the "includer" will be the parent template. So, if the child  
theme wants certain PHP files included in say the footer, then either  
it should copy over the footer.php and modify it, or the parent  
footer.php has to be relativised to the template (please forgive  
errors in the off the cuff PHP below):

     if( is_file(TEMPLATEPATH . "/custom-footer.php") )
         include_once(TEMPLATEPATH . "/custom-footer.php");

Is this the right approach?

By the same token, since the primary stylesheet (style.css) is located  
in the child theme, any relatives URLs in the style sheet (e.g:  
background: url(images/xyz.png) ....) will be resolved relative to the  
child theme -- so if the parent "images" directory contains icons and  
such, they will not appear in the child theme. Is that also true?

Finally, for theme options in the DB obtained using get_option(), the  
child theme will use all the options set for the parent since it (by  
default) inherits the parent's functions.php and other files (where,  
typically, options are set, read and used). Unless, once again, the  
options names are relativised to the theme name. Yes? AFAIK, there is  
no well-defined theme identifier that WP uses, and the option name  
used by the theme in get_option(), etc, can be any arbitrary string.  
Assuming that's true, the one way of relativising the option name that  
immediately comes to mind, is to use basename(TEMPLATEPATH) and use  
that as the option name. Is this a good approach?

Some background: why am I interested in all this? I want to be able to  
offer my theme users the ability to customise the theme and one neat  
way to do that (as suggested here) is to fork it into a child theme  
that they can then customise by editing pre-created and initially  
empty files in the theme editor (e.g: custom.css, footer-custom.php,  
etc). They can even add their own icons and background images and  
such, if I code up support for that.

Thank you,

	--ravi



More information about the wp-hackers mailing list