onethousandseas
Member
Posted 2 years ago #
If I want to make extra custom templates for my theme, is it possible to put it in a subdirectory within the theme directory to reference it?
So if the code at the top of a custom page were this:
<?php
/*
Template Name: Snarfer
*/
?>
how would I reference that if I were to put snarfer.php inside a directory named "extra-templates"?
You can easily put .php files in subdirectories and call them using get_bloginfo('template_url').'/subdirectory/somefile.php'. I don't know if WP will recognize a template file if you put it in a subdirectory. Have you tried that?
onethousandseas
Member
Posted 2 years ago #
Yep, I put it inside a subdir, but it didn't work when I simply tried to call it through the control panel.
kvcrawford
Member
Posted 2 years ago #
I wish it were possible to put custom page templates in a subdirectory, and still choose them in the "Template" <select> box from "Edit Pages" in the admin panel. It would keep the template's folder a lot cleaner when using a lot of custom page templates.
It would also be nice if you could keep your stylesheet(s) in their own "./css/" directory.
metal450
Member
Posted 2 years ago #
Re: kvcrawford - I couldn't agree more...my theme directory is a mess, and I've resorted to just trying to name everything to keep them together (i.e. pg_xx.php so all my custom page templates get alphabetized next to each other, etc)
metal450
Member
Posted 2 years ago #
A simple solution this is to use the template_redirect hook, and call a function in which you to load your templates from wherever you want, i.e.
add_action('template_redirect', 'template_overrides');
function template_overrides()
{
if( is_page('potd') ):
include(HOMEPATH . '/potd_/potd.php');
exit;
//fallthrough to default
endif;
}
:)