就像Rarst回答的那样,您确实可以做到这一点,而无需编辑核心文件,也无需删除页面属性元框,只需稍加修改即可使用相同的代码创建。下面的代码是/admin/include/meta框的代码。phpand i添加了a注释,以显示额外页面模板选项的位置:
function page_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {
$pages = wp_dropdown_pages(array(\'post_type\' => $post->post_type, \'exclude_tree\' => $post->ID, \'selected\' => $post->post_parent, \'name\' => \'parent_id\', \'show_option_none\' => __(\'(no parent)\'), \'sort_column\'=> \'menu_order, post_title\', \'echo\' => 0));
if ( ! empty($pages) ) {
?>
<p><strong><?php _e(\'Parent\') ?></strong></p>
<label class="screen-reader-text" for="parent_id"><?php _e(\'Parent\') ?></label>
<?php echo $pages; ?>
<?php
} // end empty pages check
} // end hierarchical check.
if ( \'page\' == $post->post_type && 0 != count( get_page_templates() ) ) {
$template = !empty($post->page_template) ? $post->page_template : false;
?>
<p><strong><?php _e(\'Template\') ?></strong></p>
<label class="screen-reader-text" for="page_template"><?php _e(\'Page Template\') ?></label><select name="page_template" id="page_template">
<option value=\'default\'><?php _e(\'Default Template\'); ?></option>
<?php page_template_dropdown($template); ?>
// add your page templates as options
</select>
<?php
} ?>
<p><strong><?php _e(\'Order\') ?></strong></p>
<p><label class="screen-reader-text" for="menu_order"><?php _e(\'Order\') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>
<p><?php if ( \'page\' == $post->post_type ) _e( \'Need help? Use the Help tab in the upper right of your screen.\' ); ?></p>
<?php
}
不知道这是否是对您的修复,但当我需要在插件内置主题中显示帖子类型时,我有一个更笑脸的案例,为此我使用了
add_filter(\'the_content\', \'my-function\');
我的函数创建了要显示的输出。
另一种选择是让插件在当前主题目录中创建模板文件,如下所示:
function create_plugins_theme_file(){
$file_name = TEMPLATEPATH . \'/\' . $tamplate_name . \'.php\';
$handle = fopen($file_name, \'w\') or wp_die(\'Cannot open file for editing\');
$file_contents = <<<OUT
<?php
/*
Template Name: $tamplate_name
*/
?>
//you theme file here
OUT;
fwrite($handle, $file_contents);
fclose($handle);
}
您可以在第一次检查文件是否存在后运行此操作
if(!file_exists( $file_name)){create_plugins_theme_file();}
希望其中一个有帮助。