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 have a group of themes that a client needs consolidated into one. Everything is fairly straight forward, except each theme has theme-specific page templates. Instead of pooling all the template files together in the new master theme, how can I reduce them down to one dynamic template that displays differently depending on a chosen theme option?

When searching myself I came across the template_include filter, which looks like it could be used to override the template that is used, but I'm not sure this is the right solution or how it would be implemented in this case.

Another idea I have would be to just use conditional includes inside the "master" template.

Any suggestions would be much appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Personally, I build everything within index.php of each template. I then do conditional checks.

Example:

if(is_front_page()){
    // Home page layout
} elseif(is_page()){
    // General page layout
    if(is_page('contact')){
        // Page layout specific to the contact page
    } elseif(is_page('about')){
        // Page layout specific to the about page
    }
}

Read more on conditional tags.

share|improve this answer
    
That is considered a bad practice. the Template Hierarchy exists for a reason. Using conditionals like that makes for long, harder to read template files and requires evaluating unnecessary PHP statements. The exact same templates could be created with front-page.php, page.php page-contact.php and page-about.php, respectively. –  mrwweb May 22 '12 at 3:08
1  
@mrwweb Both approaches are valid and may be appropriate in certain cases (that's why these conditionals exist). Please do not try to give the impression that your preference is generally accepted and always to be followed. –  toscho May 22 '12 at 3:27
1  
Maybe I worded this too strongly, but I did go to the Codex to double-check what I thought I had read before. "If your Theme needs to have even more control over which Template files are used than what is provided in the Template Hierarchy, you can use Conditional Tags." That strikes me as a best practice recommendation. I see that it's not a Theme Review Requirement, but it is a recommendation. I'm not arguing against all conditional tags, just ones that replace the template hierarchy. –  mrwweb May 22 '12 at 3:40
    
In the end, I didn't really need to get tricky with page templates at all. All of the themes being consolidated were variations on the same layout, so the framework between them was essentially the same - not much needed to be tweaked for it to work. Great comments! –  Evan Mattson Jul 4 '12 at 21:12

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.