Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress: Load templates from within a plugin
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
You can’t perform that action at this time.