没有获取插件中制作的模板的内容
Not getting the content of template made in plugin
我已经借助这段代码在我的插件中创建了一个模板
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;
}
我已经借助这段代码在我的插件中创建了一个模板
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;
}