未获取插件中制作的模板的内容



在代码的帮助下,我在插件中创建了一个模板

function ldc_add_thanku_page_template ($templates) {
$templates['thanku.php'] = 'Thanku Template';
return $templates;
}
function ldc_redirect_thanku_page_template ($template) {
if ('thanku.php' == basename ($template))
$template = PLUGIN_PATH .'templates/public/thanku.php';
return $template;
}

但是当我把这个模板分配给任何页面时,我都不会得到里面的内容。现在我添加了一个非常简单的代码,有人能帮我吗。

<?php  
/* Template Name: Thanku Template */
echo "<h1>Hello</h1>"; 
?>

您的代码将无法在最新的WordPress版本上工作,此代码将在4.7 以下工作

试试这个

function ldc_add_thanku_page_template ($templates) {
$templates['thanku.php'] = 'Thanku Template';
return $templates;
}
function ldc_redirect_thanku_page_template ($template) {
$post = get_post();
$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
if ('thanku.php' == basename ($page_template))
$template = WP_PLUGIN_DIR .'/mypluginname/thanku.php';
return $template;
}

最新更新