Hey,
I was wondering if someone can help me?
Is it possible to add a template page inside a plugin? Reason asking is, it would be easier for me to manage instead of adding the same template page to every theme.
Thanks! Joe.
joedajigalo said
Hey,I was wondering if someone can help me?
Is it possible to add a template page inside a plugin? Reason asking is, it would be easier for me to manage instead of adding the same template page to every theme.
Thanks! Joe.
yes http://stackoverflow.com/questions/4647604/wp-use-file-in-plugin-directory-as-custom-page-template
Hey!
Thanks for the link. I did try it out, but I might be lost at some code. The below is a sample of the code set up. I didn’t want to paste the whole code in the thread. Basically, I am using this:
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wp;
$plugindir = dirname( __FILE__ );
//A Specific Custom Post Type
if ($wp->query_vars["pagename"] == 'Service') {
$templatefilename = 'page-service.php';
$return_template = $plugindir . '/themefiles/' . $templatefilename;
do_theme_redirect($return_template);
}
}
The plugin shows up and works perfectly (it’s a custom post type, not sure if this will make a difference).
But the page name “Service” is not showing in the drop down menu of “Add Page”. Here’s a quick snapshot of the coding:
Hey Guys,
Ignore my 2nd post, I got it working. I supposed nothing is suppose to show up in the “Add Page” dropdown menu. Basically, it replaces a specific page. In this case, which I wanted to replace the post type archive page, and so here is the code that made it work:
//Template fallback
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wp;
$plugindir = dirname( __FILE__ );
//A Specific Custom Post Type
if ($wp->query_vars["post_type"] == 'service') {
$templatefilename = 'archive-service.php';
if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = $plugindir . '/themefiles/' . $templatefilename;
}
do_theme_redirect($return_template);
}
}
function do_theme_redirect($url) {
global $post, $wp_query;
if (have_posts()) {
include($url);
die();
} else {
$wp_query->is_404 = true;
}
}
Thanks! Joe.


