douzachan4578 2014-08-15 15:40
浏览 64
已采纳

wordpress - 动态侧边栏不会包含任何小部件

Here is the code in functions.php:

register_sidebar(array(
    'name'=> 'Home Page Advanced Search',
    'id' => 'custom'
));

register_sidebar(array(
    'name'=> 'Profile Picture Upload',
    'id' => 'pic upload'
));

Then, I use the two sidebars in my template like this:

?php if ( is_active_sidebar( 'custom' )) : ?>
            <div id="widget-area">              
                <?php dynamic_sidebar( 'custom' ); ?>
            </div>
<?php endif; ?>


<?php if ( is_active_sidebar( 'pic upload' )) : ?>
            <div id="upload-photo-area">
                <?php dynamic_sidebar( 'pic upload' ); ?>
            </div>
<?php endif; ?> 

The sidebar with id='custom' works fine. I am able to put widgets in it in my dashboard and display them. The sidebar with id='pic upload' is not working correctly. All widgets that I put inside of it do not stay there (in the dashboard API) and, therefore, do not display on my page.

All help is appreciated. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzhan8652 2014-08-15 15:43
    关注

    You can't have a space in the name of a sidebar. As per the codex

    If you name your own ID values in the register_sidebar() WordPress function, you might increase readability of the code. The ID should be all lowercase alphanumeric characters and not contain white space. You can also use the - and _ characters. IDs must be unique and cannot match a sidebar name. Using your own IDs can also make the sidebar name translatable.

    I added the emphases. Change pic upload to pic-upload or pic_upload should fix that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据