最重要的get_page_template()
只是一个快速的破解。它不允许从管理屏幕中选择模板,页面段塞被硬编码到插件中,因此用户无法知道模板来自何处。
The preferred solution 将遵循this tutorial 它允许您在插件的后端注册页面模板。然后它就像其他模板一样工作。
/*
* Initializes the plugin by setting filters and administration functions.
*/
private function __construct() {
$this->templates = array();
// Add a filter to the attributes metabox to inject template into the cache.
add_filter(\'page_attributes_dropdown_pages_args\',
array( $this, \'register_project_templates\' )
);
// Add a filter to the save post to inject out template into the page cache
add_filter(\'wp_insert_post_data\',
array( $this, \'register_project_templates\' )
);
// Add a filter to the template include to determine if the page has our
// template assigned and return it\'s path
add_filter(\'template_include\',
array( $this, \'view_project_template\')
);
// Add your templates to this array.
$this->templates = array(
\'goodtobebad-template.php\' => \'It\\\'s Good to Be Bad\',
);
}