Answers:
就像Rarst回答的那样,您确实可以做到这一点,而无需编辑核心文件或删除页面属性metabox并使用相同的代码进行一些修改即可创建您的on。下面的代码是/admin/include/meta-boxes.php的代码,我添加了一条注释以显示您的附加页面模板选项的位置:
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');
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();}
希望其中之一能有所帮助。
我不完全确定我了解您要实现的目标,至少是为什么您希望插件做到这一点。
创建不同页面模板的正常过程是:
在您的ACTIVE主题目录中创建一个新的页面模板(复制page.php)。
更改模板的名称(在文件内部)。
/ *模板名称:全宽页面* /
将页面的代码更改为您要实现的代码。
现在,您可以创建一个新页面,然后选择要使用的“模板”。
...
我希望这是您要实现的目标?
此处的官方文档:http : //codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
这不是register_theme_directory()
被介绍的原因之一吗?
http://core.trac.wordpress.org/ticket/10467
当时这是一个与BuddyPress有关的问题,该公司想在这里和那里扔掉额外的模板。
我认为它们没有正确地列为页面模板,但是: