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.

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

报告相同问题?