我正在使用插件:WP Post-Template,它允许我使用自定义帖子类型的模板。
目前该插件监视theme root directory 对于包含以下内容的页面:
<?php
/**
* WP Post Template: Template Name
*/
?>
我正在尝试编辑插件,以便将模板文件存储在它们自己的子目录中。看看插件代码,我想我已经找到了控制在哪里监视文件的代码行,但修改它时遇到了困难
$base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
我试图查看的文件夹是:
/lp/这段代码更改了目录,但我在查看页面时看到了白色的死亡屏幕
$base = array( trailingslashit(get_template_directory().\'/lp/\'), trailingslashit(get_stylesheet_directory().\'/lp/\') );
我唯一的猜测是插件代码中还有更多需要编辑的内容
<?php
/*
Plugin Name: WP Post Template
Plugin URI: www.dotsquares.com
Description: This plugin allows theme authors to create a post tempate as well as page template for the single post.
Author: Dotsquares
Version: 1.0
Author URI: www.dotsquares.com
*/
add_action(\'add_meta_boxes\',\'wp_add_post_custom_template\');
add_action(\'save_post\',\'wp_save_custom_post_template\',10,2);
add_filter(\'single_template\',\'wp_get_custom_post_template_for_template_loader\');
add_action( \'add_meta_boxes\', \'wp_add_post_custom_template\' );
//define(\'DEF_POST\',\'nutrition_article\');
//register functon name for install plugin
register_activation_hook(__FILE__,\'wp_custom_post_template_activate\');
function wp_custom_post_template_activate() {
add_option ( \'wp_custom_post_template\',\'post\');
}
//register functon name for uninstall plugin
register_deactivation_hook( __FILE__, \'wp_custom_post_template_deactivate\' );
function wp_custom_post_template_deactivate() {
//delete otion when plugin deactivated
delete_option ( \'wp_custom_post_template\');
}
function custom_post_template_css() {
// add css files
wp_register_style(\'wp-custom-style\', plugins_url(\'/css/myStyle.css\',__FILE__ ));
wp_enqueue_style(\'wp-custom-style\');
//add js files
}
add_action( \'admin_init\',\'custom_post_template_css\');
if ( is_admin() )
{
// add link to admin menu
add_action(\'admin_menu\', \'wp_post_template_admin_menu\');
function wp_post_template_admin_menu()
{
add_menu_page( \'WP Post Template\', \'WP Post Template\', \'manage_options\', \'post_template_setting\', \'wp_post_template_setting\',plugins_url(\'ico.png\',__FILE__ ));
}
}
function wp_post_template_setting(){
_e(\'<h2>WP Custom Post Template</h2>\');
include(\'_form.php\');
}
function wp_add_post_custom_template($postType) {
if(get_option(\'wp_custom_post_template\') == \'\'){ //get option value
$postType_title = \'post\';
$postType_arr[] = $postType_title;
}else{
$postType_title = get_option(\'wp_custom_post_template\');
$postType_arr = explode(\',\',$postType_title);
}
if(in_array($postType, $postType_arr)){
add_meta_box(
\'postparentdiv\',
__(\'Template\'),
\'wp_custom_post_template_meta_box\',
$postType,
\'side\',
\'core\'
);
}
}
function wp_custom_post_template_meta_box($post) {
if ( $post->post_type != \'page\' && 0 != count( wp_get_post_custom_templates() ) ) {
$template = get_post_meta($post->ID,\'_post_template\',true);
?>
<label class="screen-reader-text" for="post_template"><?php _e(\'Post Template\') ?></label>
<select name="post_template" id="post_template">
<option value=\'default\'><?php _e(\'Default Template\'); ?></option>
<?php wp_custom_post_template_dropdown($template); ?>
</select>
<?php
}
}?>
<?php
function wp_get_post_custom_templates() {
if(function_exists(\'wp_get_themes\')){
$themes = wp_get_themes();
}else{
$themes = get_themes();
}
$theme = get_option( \'template\' );
$templates = $themes[$theme][\'Template Files\'];
$post_templates = array();
if ( is_array( $templates ) ) {
$base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
foreach ( $templates as $template ) {
$basename = str_replace($base, \'\', $template);
if ($basename != \'functions.php\') {
// don\'t allow template files in subdirectories
if ( false !== strpos($basename, \'/\') )
continue;
$template_data = implode( \'\', file( $template ));
$name = \'\';
if ( preg_match( \'|WP Post Template:(.*)$|mi\', $template_data, $name ) )
$name = _cleanup_header_comment($name[1]);
if ( !empty( $name ) ) {
$post_templates[trim( $name )] = $basename;
}
}
}
}
return $post_templates;
}
function wp_custom_post_template_dropdown( $default = \'\' ) {
$templates = wp_get_post_custom_templates();
ksort( $templates );
foreach (array_keys( $templates ) as $template )
: if ( $default == $templates[$template] )
$selected = " selected=\'selected\'";
else
$selected = \'\';
echo "\\n\\t<option value=\'".$templates[$template]."\' $selected>$template</option>";
endforeach;
}
function wp_save_custom_post_template($post_id,$post) {
if ($post->post_type !=\'page\' && !empty($_POST[\'post_template\']))
update_post_meta($post->ID,\'_post_template\',$_POST[\'post_template\']);
}
function wp_get_custom_post_template_for_template_loader($template) {
global $wp_query;
$post = $wp_query->get_queried_object();
if ($post) {
$post_template = get_post_meta($post->ID,\'_post_template\',true);
if (!empty($post_template) && $post_template!=\'default\')
$template = get_stylesheet_directory() . "/{$post_template}";
}
return $template;
}
?>