doufei2355 2013-12-13 19:13
浏览 41

Wordpress注册新的补充工具栏问题

I have a question about Wordpress register a second sidebar for a new sub-menu i will use for some blog-post on my site.(on a specific-page only)

I read how to Register a new Sidebar! In the first 3 lines of the code below you see what have saved in my themes function__php and it seems to work, i am not shure if is correct, but the Backend shows me now 2 sidebar-areas in the widget-sector.(before there was none i remember)

this i include:

**// If Dynamic Sidebar Exists
if (function_exists('register_sidebars'))
 register_sidebars(2);**
{
// Define Sidebar Widget Area 1
register_sidebar(array(
    'name' => __('Widget Area 1', 'html5blank'),
    'description' => __('Description for this widget-area...', 'html5blank'),
    'id' => 'widget-area-1',
    'before_widget' => '<div id="%1$s" class="%2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
));

// Define Sidebar Widget Area 2
register_sidebar(array(
    'name' => __('Widget Area 2', 'html5blank'),
    'description' => __('Description for this widget-area...', 'html5blank'),
    'id' => 'widget-area-2',
    'before_widget' => '<div id="%1$s" class="%2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
));

// Define Sidebar Widget Area 3
register_sidebar(array(
    'name' => __('Widget Area 3', 'html5blank'),
    'description' => __('Description for this widget-area...', 'html5blank'),
    'id' => 'widget-area-3',
    'before_widget' => '<div id="%1$s" class="%2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
));

}

Now, i am a little bit confused, because in the fist setup of my site there was a widget-area 1! that holds the head-menu, then the widget-area 2! that holds the standart-themes-sidebars: serach field and some widgetized text :P.

now i dont know how to get the second sidebar fully correct registred and how to programm the php in the copyed sidebar2.php

see here:

<!-- Sidebar -->
<aside id="sidebar">

<div class="sidebar-widget3">
<?php if(!function_exists('dynamic_sidebar2') || !dynamic_sidebar('widget-area-3')) ?>
</div>      
</aside>
<!-- /Sidebar -->

should i put the widgets(search-field and text) in my backend in the sidebar-areas or should i leave it in the widget areas?

its a generall-understanding problem for me, amd i hope someone can help me out, because i am a bloody beginner.

tnx a lot.![this is the actuall setup, that is confusing me and i like to have this steps fixed soon...

  • 写回答

1条回答 默认 最新

  • doulang6013 2014-02-02 14:51
    关注

    First off, remove this line: register_sidebars(2);**
    It's unnecessary and might screw it up. Also, your function is named register_sidebars, with an "s" at the end. Since you're using html5blank (so am I,) I can see that this is wrong.

    My function looks like this, and it works just fine. Simply replicate the register_sidebar array for as many sidebars that you need. When it comes to "where should I put this-and-that", it's up to you.

    if (function_exists('register_sidebar')) {
        register_sidebar(
            array(
                'name'          => __('Widget Area 1', 'html5blank'),
                'description'       => __('Description', 'html5blank'),
                'id'            => 'widget-area-1',
                'before_widget'     => '<div id="%1$s" class="%2$s">',
                'after_widget'      => '</div>',
                'before_title'      => '<h3>',
                'after_title'       => '</h3>'
            )
        );
    }
    

    When it comes to sidebar.php, for some reason you have called it dynamic-sidebar2, which is a function that does not exist - unless you've created it.
    Simply change it to this:

    <div class="sidebar-widget">
        <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-1')) ?>
    </div>
    
    <div class="sidebar-widget">
        <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-2')) ?>
    </div>
    
    <div class="sidebar-widget">
        <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-3')) ?>
    </div>
    

    I hope this answers your question. If it doesn't, leave a comment and I'll try to amend my answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?