Php 插件短代码在页面编辑器(管理面板)Wordpress中显示模板页面
我正在为wordpress主题创建一个插件,将模板加载到它自己的目录中,而不是将模板放置在主题中,这样我就可以独立地将模板包含在主题中,因为我已经创建了短代码,以便根据条件加载不同的模板。代码如下: 添加快捷码(“模板”、“添加模板”) 函数添加模板($atts){Php 插件短代码在页面编辑器(管理面板)Wordpress中显示模板页面,php,wordpress,Php,Wordpress,我正在为wordpress主题创建一个插件,将模板加载到它自己的目录中,而不是将模板放置在主题中,这样我就可以独立地将模板包含在主题中,因为我已经创建了短代码,以便根据条件加载不同的模板。代码如下: 添加快捷码(“模板”、“添加模板”) 函数添加模板($atts){ 提取(短码)附件(数组)( “模板”=>“ )美元(附件); 交换机($模板){ 我的问题是在一些主题中,我的插件开始在管理面板中显示页面。我有什么做错了吗?请帮助……找到解决方案,我们只需要在包含模板之前添加一个检查,确保用户不是
提取(短码)附件(数组)( “模板”=>“
)美元(附件); 交换机($模板){
我的问题是在一些主题中,我的插件开始在管理面板中显示页面。我有什么做错了吗?请帮助……找到解决方案,我们只需要在包含模板之前添加一个检查,确保用户不是管理员
add_shortcode('template', 'add_template');
function add_template( $atts) {
extract( shortcode_atts( array( 'template' => ''
), $atts ) );
switch ($template) {
case 'template1':
if ( !is_admin() ) {
include 'templates/template1.php';
}
break;
case 'template2':
if ( !is_admin() ) {
include 'templates/template2.php';
}
break;
default:
if ( !is_admin() ) {
include 'templates/template1.php';
}
break;
}
}
add_shortcode('template', 'add_template');
function add_template( $atts) {
extract( shortcode_atts( array( 'template' => ''
), $atts ) );
switch ($template) {
case 'template1':
if ( !is_admin() ) {
include 'templates/template1.php';
}
break;
case 'template2':
if ( !is_admin() ) {
include 'templates/template2.php';
}
break;
default:
if ( !is_admin() ) {
include 'templates/template1.php';
}
break;
}
}