Created
September 5, 2012 23:52
-
-
Save jbreitenbucher/3648028 to your computer and use it in GitHub Desktop.
WordPress: Load templates from within a plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_custom_archive_template($template) { | |
global $wp_query; | |
$object = $wp_query->get_queried_object(); | |
if ( 'gslstaff' == $object->post_type ) { | |
$templates = array(); | |
if ( $object->post_type ) | |
$templates[] = "archive-{$object->post_type}.php"; | |
$templates[] = 'archive.php'; | |
$template = locate_plugin_template($templates); | |
} | |
//return get_query_template( 'archive', $templates ); | |
return $template; | |
} | |
function get_custom_page_template($template) { | |
global $wp_query; | |
$id = $wp_query->get_queried_object_id(); | |
$template_slug = $wp_query->get_page_template_slug(); | |
$pagename = get_query_var('pagename'); | |
$object = $wp_query->get_queried_object(); | |
if ( ! $pagename && $id ) { | |
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object | |
$post = $wp_query->get_queried_object(); | |
$pagename = $post->post_name; | |
} | |
if ( 'gslstaff' == $object->post_type ) { | |
$templates = array(); | |
if ( $template_slug && 0 === validate_file( $template_slug ) ) | |
$templates[] = $template_slug; | |
if ( $pagename ) | |
$templates[] = "page-$pagename.php"; | |
if ( $id ) | |
$templates[] = "page-$id.php"; | |
$templates[] = 'page.php'; | |
$template = locate_plugin_template($templates); | |
} | |
//return get_query_template( 'page', $templates ); | |
return $template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment