Php 如何注册边栏wordpress
我正在制作一个wordpress模板,需要注册一个边栏。我使用函数register_sidebar()来完成它,它可以工作,但它似乎与wordpress的默认侧栏冲突。默认侧栏显示为非活动状态。如何注册默认的wordpress边栏 functios.php中的我的代码Php 如何注册边栏wordpress,php,wordpress,Php,Wordpress,我正在制作一个wordpress模板,需要注册一个边栏。我使用函数register_sidebar()来完成它,它可以工作,但它似乎与wordpress的默认侧栏冲突。默认侧栏显示为非活动状态。如何注册默认的wordpress边栏 functios.php中的我的代码 function wpb_init_widgets($id) { register_sidebar(array( 'name' => 'Sidebar-1', 'id' =>
function wpb_init_widgets($id) {
register_sidebar(array(
'name' => 'Sidebar-1',
'id' => 'sidebar-1',
'before_widget' => '<div class="sidebar-module">',
'after_widget' => '</div>',
'before_title' => '</h4>',
'after_title' => '</h4>'
));
}
add_action('widgets_init','wpb_init_widgets');
函数wpb_init_小部件($id){
寄存器侧栏(数组)(
'name'=>'Sidebar-1',
'id'=>'sidebar-1',
'在小部件'=>''之前,
'在小部件'=>''之后,
“在标题“=>”之前,
“在标题之后”=>“
));
}
添加操作('widgets_init','wpb_init_widgets');
提前感谢。尝试如下编辑代码:
function wpb_init_widgets_custom($id) {
register_sidebar(array(
'name' => 'Customsidebar-1',
'id' => 'customsidebar-id',
'before_widget' => '<div class="sidebar-module">',
'after_widget' => '</div>',
'before_title' => '</h4>',
'after_title' => '</h4>'
));
}
add_action('widgets_init','wpb_init_widgets_custom');
函数wpb_init_widgets_custom($id){
寄存器侧栏(数组)(
'name'=>'Customsidebar-1',
'id'=>'customsidebar id',
'在小部件'=>''之前,
'在小部件'=>''之后,
“在标题“=>”之前,
“在标题之后”=>“
));
}
添加操作('widgets_init','wpb_init_widgets_custom');
对于ID,您需要使用-ID
,就好像您没有设置ID参数值一样,您将在调试模式下收到E_USER_NOTICE消息。此外,ID侧边栏-1被许多主题占据,因此可能会导致冲突。让我知道这是否有帮助,以及默认侧边栏是否仍然处于非活动状态。
正如Leland所建议的,还可以尝试更改函数名称,这可能也是冲突的原因,可能比我上面写的更可能。因此,新函数名更改为wpb_init_widgets_custom。尝试这样做
add_action( 'widgets_init', 'function_widgets_init' );
function function_widgets_init()
{
register_sidebar( array (
'name' => __( 'Sidebar Widget Area', 'textdomain' ),
'id' => 'primary-widget-area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action('widgets_init','function_widgets_init');
函数函数
{
寄存器侧栏(数组)(
'name'=>\('Sidebar Widget Area','textdomain'),
'id'=>'主窗口小部件区域',
'before_widget'=>'”,
'after_widget'=>“ ”,
“在标题“=>”之前,
“在标题“=>”之后,
) );
}
hmm,“wordpress的默认侧栏显示为非活动”是什么意思?@L你知道当你有一个主题,你转到widgets,那里有一个充满widgets的侧栏吗?该侧边栏显示为非活动状态,无法使用。我对wordpress不是很有经验,所以这可能是个愚蠢的问题。嘿,看起来wpb_init_widgets()
与WP引导主题使用的函数相同:。如果这是您使用引用代码的主题,那么它将与现有函数冲突。试着给它起个别的名字。按照你的建议做了,问题还在继续。我删除了我的主题,并再次上传它与改变功能,结果是一样的。当我转到Appearence>Widgets时,我的自定义侧栏在那里,但在可用的小部件下面有一个明确的侧栏。消息说:“此侧边栏不再可用,并且不会显示在您网站的任何位置…”帮助?您使用的主题是什么?我正在制作自己的主题。