Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress自定义侧栏模板未激活_Php_Wordpress_Sidebar - Fatal编程技术网

Php Wordpress自定义侧栏模板未激活

Php Wordpress自定义侧栏模板未激活,php,wordpress,sidebar,Php,Wordpress,Sidebar,我正在一个wordpress网站上工作(我的第一个网站),在那里我想为一个特定的页面模板使用一个特定的边栏。边栏不是常规的小部件区域,而是一个调用表单的另一个模板(boeking.php)的模板(sidebar-2.php) 我使用默认的page.php和sidebar.php作为起点,复制了几乎所有内容,因此为页面创建了一个模板(reisbeschrijving.php),该模板使用get\u sidebar('2')调用sidebar-2。我还创建了一个模板边栏-2.php: 它一开始工作正

我正在一个wordpress网站上工作(我的第一个网站),在那里我想为一个特定的页面模板使用一个特定的边栏。边栏不是常规的小部件区域,而是一个调用表单的另一个模板(boeking.php)的模板(sidebar-2.php)

我使用默认的page.php和sidebar.php作为起点,复制了几乎所有内容,因此为页面创建了一个模板(reisbeschrijving.php),该模板使用
get\u sidebar('2')
调用sidebar-2。我还创建了一个模板边栏-2.php:

它一开始工作正常,但当我在网站的另一部分工作时,它突然停止了工作。页面模板工作正常,但它不加载侧栏-2,因为
处于活动状态\u侧栏()
返回false。但是,我不知道为什么它返回false。当我在reisbeschrijving.php中调用
get\u sidebar()
(默认值)时,它确实显示sidebar.php,并且
处于活动状态\u sidebar()
返回true。如果我删除If
is\u active\u sidebar()
子句,sidebar-2显示得很好。sidebar.php和sidebar-2.php都位于(子主题的)同一文件夹中

我错过什么了吗?我应该在页眉或其他地方注册新的边栏-2模板吗?我知道自定义动态边栏和widget区域是这样的,但这是一个全新的模板,我想我不必这么做(我尝试过了,但没有用)。
任何关于为什么
处于活动状态\u侧边栏
在我的第二个侧边栏上返回“false”的提示都将不胜感激

1st Register侧栏-functions.php

function my_custom_sidebar() {
    register_sidebar(
        array (
            'name' => __( 'Custom', 'your-theme-domain' ),
            'id' => 'custom-side-bar',
            'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
            'before_widget' => '<div class="widget-content">',
            'after_widget' => "</div>",
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        )
    );
}
add_action( 'widgets_init', 'my_custom_sidebar' );
函数我的自定义工具条(){
寄存器侧栏(
排列(
'name'=>\('Custom','your theme domain'),
'id'=>'自定义侧栏',
'description'=>\('Custom Sidebar','your theme domain'),
'在小部件'=>''之前,
'在小部件'=>''之后,
“在标题“=>”之前,
“在标题“=>”之后,
)
);
}
添加操作('widgets_init','my_custom_边栏');
  • 将此代码放入模板中

    如果(是活动的侧栏(“自定义侧栏”): 动态侧栏(“自定义侧栏”); endif


  • 这将100%起作用。

    您需要在functions.php文件中注册侧栏。请查看
    register\u sidebar()
    文档。感谢您的回复!我尝试再次注册它,并将侧边栏-2模板中的代码更改为Ravi指示的代码,但仍然无法工作。还有其他建议吗?