我在WordPress上为自定义主页创建了一系列新的侧边栏。保存每个后,他们工作并继续工作。一旦我返回到Admin区域中的Widget区域,只有那些小部件是空白的,然后它们将从主页中丢失。下面的Functions.php代码用于添加的侧边栏
// Widgetized Header
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Header',
'id' => 'Header',
'description' => 'Header Sidebar for Search',
'before_widget' => '<ul class="right"><li class="has-form">',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
// Homepage Sidebar for Mailchimp
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Mailchimp Widget',
'id' => 'HomeWidget1',
'description' => 'Homepage mailchimp area',
'before_widget' => '<ul class="home-widget"><li class="has-form">',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
// Homepage Sidebar for Twitter
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Twitter Widget',
'id' => 'HomeWidget2',
'description' => 'Homepage twitter area',
'before_widget' => '<ul class="home-widget"><li>',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
// Homepage Sidebar for Promo Ad
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Promo Ad',
'id' => 'HomeWidget5',
'description' => 'Homepage Promo Ad',
'before_widget' => '<ul class="home-widget">',
'after_widget' => '</ul>',
));
}
// Homepage Sidebar for Archives
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Archive Widget',
'id' => 'HomeWidget3',
'description' => 'Homepage Widget for Archives',
'before_widget' => '<ul class="home-widget"><li class="has-form">',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
// Homepage Sidebar for Archives
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Social Widget',
'id' => 'HomeWidget4',
'description' => 'Homepage Widget for Social Nav',
'before_widget' => '<ul class="home-widget"><li>',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
答案 0 :(得分:0)
有一些事情可能导致这个问题。
1)register_sidebar()不需要在这里包含条件。它是一个WordPress核心功能,所以它不会去任何地方。这样做会很好:
register_sidebar(array(
'name' => 'Homepage Twitter Widget',
'id' => 'HomeWidget2',
'description' => 'Homepage twitter area',
'before_widget' => '<ul class="home-widget"><li>',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
2)使用动作挂钩widgets_init
加载注册。对于register_sidebar的多个实例,我建议在函数中包装所有实例,然后挂钩该函数。例如:
function myPrefix_widgets_init() {
register_sidebar(array(
'name' => 'Homepage Mailchimp Widget',
'id' => 'HomeWidget1',
'description' => 'Homepage mailchimp area',
'before_widget' => '<ul class="home-widget"><li class="has-form">',
'after_widget' => '</li></ul>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
// Register the rest of the widgets here.
}
add_action( 'widgets_init', 'myPrefix_widgets_init' ); //<-- This is the action hook
Justin Tadlock的这篇文章现在已有几年了,但仍然很精彩地详细解释了WordPress如何处理小组化的侧栏:http://justintadlock.com/archives/2010/11/08/sidebars-in-wordpress