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.
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 saidHey,
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.
How do you define which page it’s supposed to replace?
This is my code:
// Add callback to admin menu add_action( 'template_redirect', 'uploadr_redirect' ); // Callback to add menu items function uploadr_redirect() { global $wp; $plugindir = dirname( __FILE__ ); // A Specific Custom Post Type if ( $wp->query_vars["post_type"] == 'uploadr' ) { $templatefilename = 'custom-uploadr.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; } }
as well as a page named uploadr. But I’m not seeing any change that I added in my custom-uploadr.php file.
PLEASE HELP!!! I’ve spent at least 8 hours reaserching this with no avail.
Thanks is andvance.