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.

One section of my website is going to be completely different visually than the rest of the pages, is there a way to apply a WP Theme to specific page templates ?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

In fact there is, using template_redirect, which you would put in the functions.php file - Here's what I use:

function uniquename_default_template() {
    if(get_post_type() == 'posttype') : /* You could use is_single() instead of get_post_type() == '' or any type of conditional tag) */
    include(TEMPLATEDIR . 'path/to/theme/file.php'); /* You could use TEMPLATEDIR to get a file from a template folder, or PLUGINDIR to get a file from the plugins directory - doesn't support HTTP requests */
    exit; endif;
}
add_action('template_redirect', 'uniquename_default_template');

The above code checks for a post_type called posttype, if it is, it will include the PHP file specified in the include statement by redirecting the template using the template_redirect function.

share|improve this answer
    
Ok so I put this function into the functions.php of my main theme. Then I have a second theme that I want to apply only to a specific page template. I can test this condition on the first line of your function with if(is_page_template('template_special_area.php') ). Then I have to include this said template, how do I do that? Doesn't TEMPLATEDIR point to the main theme fodler? –  mike23 Mar 7 '11 at 9:46
1  
@mike23 - that's just example code, jared suggested to have some template inside a plugin but you can naturally use some template from within another theme and then use TEMPLATEDIR to point to the right file. –  hakre Mar 7 '11 at 11:22
    
@mike23 - hakre is right, you would need to use TEMPLATEDIR (which points to /public_html/wp-content/themes/) if the file is in your themes folder. But my code may be a little buggy, I haven't tested it much but it might just work for what you need. Either way, the function you're looking for to use is template_redirect - I wouldn't count on my code above to work 100%. –  Jared Mar 7 '11 at 11:31
    
@mike23 - I revised my code a bit, it is in the proper format now and above is how it should be used. –  Jared Mar 8 '11 at 7:23
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.