Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I apologize if this questions has already been answered, I have a feeling I'm just not using the right terminology for my search.

I'm in the process of building a base theme for my employer. One of the things we want to do with this new theme is have the option to switch from a standard template to one that's been Zurbified. The way I'd prefer to handle this is by having an admin panel checkbox.

Within the theme itself we want to have 2 separate folders that contain the actual theme template files (Ex: theme_folder/normal/page.php || theme_folder/zurb/page.php).

How would I go about properly processing this? Is there a hook/filter that allows you to specify which sub folder to use in the specific situation? From what I read its possible to have the sub directories house the template page files,
http://nacin.com/2012/03/29/page-templates-in-subdirectories-new-in-wordpress-3-4/
, but I'm not finding the call I need to tell Wordpress to use the specific subs.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

When I want to change a specific part of template, such as header OR footer then I use conditions like this -

if(is_404()) {
    get_header(`error`);    //loads header-error.php
} else {
    get_header();           //loads header.php
}

In your case, you want to load a completely different template, Now the only action hook I can imagine is - template_redirect, Which can be used to tell wordpress to load a different template as per conditions.

Example -

function wpse62337_zurbified() {
    if ( CONDITION ) {
        include (TEMPLATEPATH . '/zurb/page.php');
        exit;
    }
}
 
add_action('template_redirect', 'wpse62337_zurbified');
share|improve this answer
    
From my preliminary tests this appears to be what I was looking for. Thank you! –  voodooGQ Aug 19 '12 at 19:54
add comment

If I understand you correctly, you want to have one theme and just have some conditionals to load different templates based on a checkbox.

The article you linked to deals only with page templates and does not apply to all the other template files within the WordPress ecosystem, for example for posts or categories (though you can also add this functionality to posts with some coding).

If you want to apply a technique that deals with all WordPress templates your probably better off using get_template_part and having the "zurb" version as a sub-folder within the default theme. Then you can use some conditionals to load what you want.

If your only talking about page templates, WordPress auto scans the theme directory including subfolders, so as long as you structure the template header it will find it, this includes child themes.

tl;dr you don't have to do anything besides have the required header

For example

<?php
/*
Template Name: Snarfer
*/
?>

Of course if there are a lot of files to scan and subdirs you will take a performace hit.

Also be be advised that:

Renaming a page template — and that includes moving all of top-level page templates into a directory — will unassign that page template for all pages currently using it. This is a new tool in your toolbox, but use it wisely
-Nacin

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.