Create custom page templates with plugins?
// Publication page template -----------------------
//Add our custom template to the admin's templates dropdown
add_filter( 'theme_page_templates', 'pluginname_template_as_option_publications', 10, 3 );
function pluginname_template_as_option_publications( $page_templates, $theme, $post ){
$page_templates['template-publication.php'] = 'Publications new shahinn';
return $page_templates;
}
//When our custom template has been chosen then display it for the page
add_filter( 'template_include', 'pluginname_load_template_publications', 99 );
function pluginname_load_template_publications( $template ) {
global $post;
$custom_template_slug = 'template-publication.php';
$page_template_slug = get_page_template_slug( $post->ID );
if( $page_template_slug == $custom_template_slug ){
return plugin_dir_path( __FILE__ ) . $custom_template_slug;
}
return $template;
}
//end page template-------------------------

No comments: