/* 加载页面模板 */
add_filter( 'page_template', 'marker_page_template' );
function marker_page_template( $page_template ) {
if ( get_page_template_slug() == 'markerv' ) {
$page_template = MARKER_DIR . '/templates/markerv.php';
}
if ( get_page_template_slug() == 'test' ) {
$page_template = MARKER_DIR . '/templates/test.php';
}
return $page_template;
}
/* 添加到页面属性模板中 */
add_filter( 'theme_page_templates', 'marker_add_template_select', 10, 4 );
function marker_add_template_select( $post_templates, $wp_theme, $post, $post_type ) {
$post_templates['markerv'] = __( 'markerv' );
$post_templates['test'] = __( 'test' );
return $post_templates;
}
模板文件:markerv.php
模板文件路径:/templates/markerv.php
显示在页面属性中的模板名称:$post_templates[‘markerv’] = __( ‘模板名称’);