[wp-trac] [WordPress Trac] #7492: Template tag: wp_include_file
WordPress Trac
wp-trac at lists.automattic.com
Sun Aug 10 18:59:09 GMT 2008
#7492: Template tag: wp_include_file
-------------------------+--------------------------------------------------
Reporter: KKWangen | Owner: anonymous
Type: enhancement | Status: new
Priority: normal | Milestone: 2.7
Component: Template | Version:
Severity: normal | Keywords:
-------------------------+--------------------------------------------------
This is related to changeset r8497 that let you override the templates of
a Parent Theme in a Child Theme.
But if a theme uses the code:
{{{
<?php include (TEMPLATEPATH . '/file.php'); ?>
}}}
to include misc. template files, you can not override that file in Child
Theme.
So I thought it might be a better idea to have template tag for including
misc. template files in a theme, so they can be overridden in a child
theme.
The code I've played with to make it work looks like this:
{{{
function wp_include_file($name = '', $dir = '') {
$file = "{$name}.php";
$include = apply_filters("include_{$name}", STYLESHEETPATH .
"{$dir}/{$name}.php" );
if ( file_exists( $include) )
include( $include);
elseif ( file_exists( TEMPLATEPATH . "{$dir}/{$name}.php") )
include( TEMPLATEPATH . "{$dir}/{$name}.php");
}
}}}
$name is the name of the file without the .php, so to include
searchform.php you get a code like:
{{{
<?php wp_include_file('searchform'); ?>
}}}
the $dir variable will let theme authors put the misc template files they
in subdirectory of their theme's root directory.
Example: a theme author add their searchform.php file in a /includes
subdirectory. Then they can include the file in the theme with:
{{{
<?php wp_include_file('searchform','/includes'); ?>
}}}
To override the file in a Child Theme, you can either add it in using the
same structure as the Parent Theme: /childtheme/includes/searchform.php
''Or'' you can filter the path in the Child Theme's function php file:
{{{
function my_searchform() {
$my_searchform = STYLESHEETPATH . '/searchform.php';
return $my_searchform;
}
add_filter('include_searchform','my_searchform');
}}}
--
Ticket URL: <http://trac.wordpress.org/ticket/7492>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list