Hi quick question i don’t believe an answer is essential but its is more of a query…as my code technically works.
so i am creating a WordPress plugin to change the theme of a page upon meeting a certain requirement.
Here is my code.
<?php
add_action('template_redirect', 'redirectTheme');
function loadTheme($url) {
global $post, $wp_query;
if (have_posts()) {
echo 'requiring theme';
require($url);
die();
} else {
$wp_query->is_404 = true;
}
}
function redirectTheme() {
if(is_page('Gallerie')){
$templatefilename = '/theme1.php';
if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = THEME_DIR . $templatefilename;
}
loadTheme($return_template);
}
}
?>
Now that code works perfect however….. when setting the page to require to index.php opposed to theme1.php it will not load the page i have made a copy of the files so the required pages are exactly the same just different name so it would seem WordPress will not allow index.php as an included file, any one know why?
$templatefilename = '/theme1.php';