[wp-hackers] Custom Templates in sub-folder

Sudar Muthu sudar at sudarmuthu.com
Mon Sep 14 17:16:17 UTC 2009

Hello all,

I digged a little deeper into the code and found that there is a discrepancy
in the way page templates are handled. (I checked WordPress 2.8.4 code)

First in the write page and edit page admin pages, the list of page
templates is retrieved using the get_themes() function in
wp-include/theme.php file. In this function, we are iterating in the current
directory and all sub directory to get template files. So if I place a
page-template file inside a sub directory (single level) then it will be
displayed in the admin pages.

When the page is rendered, locate_template() function again from
wp-include/theme.php file is invoked. In this function, we are checking for
the page template only from the theme's directory and not in sub-directory.
So by default the page.php template will be used.

This is surely a bug, but I am not sure where the fix should go. Placing
page-template files in a separate directory could be handy. In that case we
might have to modify locate_template() function.

With Regards,


On Sat, Sep 12, 2009 at 00:47, Steve Bruner [SlipFire] <sbruner at slipfire.com
> wrote:

> Created a custom template and placed it in a sub-directory of my theme.
> When I look at the template list on Add New Page, my custom template is
> listed (only seems to work one folder level back).  However, WP uses
> Page.php (in theme root), instead of my custom template.
> Is this a bug in WP or am I missing something?
> Steve
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list