2016-09-28 32 views
1

喜同胞程序员,WordPress的dynamic_sidebar不解析,删除改变

我是比较新的WordPress的,因为我通常使用Typo3的,所以我有一个关于在WP定制工具条的问题。

我在我的functions.php下面的代码

function custom_sidebars() 
{ 

    register_sidebars(4, array 
    (
    'name' => __('Panel Startseite %d', 'me'), 
    'id' => 'panel-home-%d', 
    'description' => 'Widget Position for home panel', 
    'class' => 'panel-sidebar', 
    'before_widget' => '<div class="widget-panel-%d">', 
    'after_widget' => '</div>', 
    'before_title' => '<h2 class="panel-title">', 
    'after_title' => '</h2>' 
)); 

    $args2 = array 
    (
    'name' => __('Short Bio Sidebar', 'me'), 
    'id' => 'shortbio-id', 
    'description' => 'Widget Position for short bio', 
    'class' => 'shortbio-sidebar', 
    'before_widget' => '<div class="widget-bio">', 
    'after_widget' => '</div>', 
    'before_title' => '<h2 class="widgettitle">', 
    'after_title' => '</h2>' 
); 
    register_sidebars(1, $args2); 

} 

add_action('widgets_init', 'custom_sidebars'); 

我想在我的主页,并在页脚另一个小字段添加4块板的信息为笔者添加生物或改变它。

这里是我的index.php我的代码

<div id="main"> 
    <div class="wrapper"> 
    <div class="col-sm-6"> 
     <div class="inner"> 
     <?php dynamic_sidebar('panel-home-1'); ?> 
     </div> 
    </div> 
    <div class="col-sm-6"> 
     <div class="inner"> 
     <?php dynamic_sidebar('panel-home-2'); ?> 
     </div> 
... and so on 

相同的实现是在footer.php在给定位置。

我的问题是:

  • 内容我通过后台菜单主题添加 - >小部件不显示,且被删除下一次我打开后端。
  • 有在的wp-content /无的debug.log错误,我固定所有常见的激活WP-config.php文件中的选项后

我怎样才能解决这个问题,什么是我的基本思路错误?

最好的问候sKylo

回答

0

你的代码都很好。只有一个错误,您使用%d连接您的id后的小数。但是这不是必须的,因为%d会自动添加到提供的ID中。请在此答案结尾处查找代码链接。

所以,我从你的代码的ID部分删除%d,现在它的工作原理。

解决方案:

function custom_sidebars() 
{ 

    register_sidebars(4, array 
    (
    'name' => __('Panel Startseite %d', 'me'), 
    'id' => 'panel-home', 
    'description' => 'Widget Position for home panel', 
    'class' => 'panel-sidebar', 
    'before_widget' => '<div class="widget-panel">', 
    'after_widget' => '</div>', 
    'before_title' => '<h2 class="panel-title">', 
    'after_title' => '</h2>' 
)); 

    $args2 = array 
    (
    'name' => __('Short Bio Sidebar', 'me'), 
    'id' => 'shortbio-id', 
    'description' => 'Widget Position for short bio', 
    'class' => 'shortbio-sidebar', 
    'before_widget' => '<div class="widget-bio">', 
    'after_widget' => '</div>', 
    'before_title' => '<h2 class="widgettitle">', 
    'after_title' => '</h2>' 
); 
    register_sidebars(1, $args2); 

} 

add_action('widgets_init', 'custom_sidebars'); 

<div id="main"> 
    <div class="wrapper"> 
    <div class="col-sm-6"> 
     <div class="inner"> 
     <?php dynamic_sidebar('panel-home'); ?> 
     </div> 
    </div> 
    <div class="col-sm-6"> 
     <div class="inner"> 
     <?php dynamic_sidebar('panel-home-2'); ?> 
     </div> 
... and so on 

你不需要%d增加register_sidebars的ID。请阅读codex, 它说:

“%d”被自动添加到第一个之后提供的“id”值;例如“边栏-1”,“边栏-2”,“边栏-3”等。

+0

thx很多队友!它现在按预期工作。但是等等,小部件管理界面上有很多不活动的边栏。我如何删除它们,也许隐藏它们? – Marc

+0

不客气。点击小部件,它会显示你在它的底部删除选项。 –

+0

如果答案解决了您的问题,请不要忘记将其作为正确答案进行检查。接受答案可以帮助其他人跟踪您的问题已解决问题。 –