• I use 3 different sidebars in my theme. There is a home, pages and default sidebar. I have had success with making one sidebar widget friendly… but 3?

    Php is not my strong suit. Here is the code that I tried in function.php of the theme:

    <code>
    < ?php
    if ( function_exists('register_sidebar') )
    register_sidebars(1, array('name'=>'Sidebar') );
    register_sidebars(1, array('name'=>'Home') );
    register_sidebars(1, array('name'=>'Pages') );
    ?>

    </code>

    Errors occured when commenting on a blog post, which leads me to believe it’s not right. It appeared to work, but then the errors…

    Anyone have any ideas on how to create the right code?

    Thanks,

    Pwinkle
    p.s.
    I’m using WP 2.02.

Viewing 12 replies - 1 through 12 (of 12 total)
  • if you’re using the sidebars widget plugin, you shouldn’t need to make changes to functions.php. you should only need to place the proper calls to the sidebars in your theme’s pages. unless I’m not understanding the problem correctly.

    URL ?

    Thread Starter perywinkle

    (@perywinkle)

    I would like to make all 3 sidebars widget-able.

    I would also like to name the sidebars “Home”, “Pages”, and “Sidebar” ( Default). Rather than “sidebar1”, “sidebar2”, “sidebar3” in the admin section.

    I placed this code into the functions.php file:

    <? php
    if ( function_exists('register_sidebar') )
    register_sidebar(3);
    ?>

    Creates sidebar1, sidebar2, and sidebar3 in the admin section – which works for me, but how do your teammates know which sidebar ‘sidebar1’ is with out trial and error.

    Proper names for the sidebars is what i’m after.

    I think I have to name them in the functions.php of the theme.


    Widget API ?

    void register_sidebars ( [ int count [, mixed args ]] )
    Registers one or more sidebars to be used in the current theme. Most themes have only one sidebar. For this reason, the count parameter is optional and defaults to one.
    The args parameter will be passed to register_sidebar and follows its format, with the exception of the name, which is treated with sprintf() to insert or append a unique number to each sidebar if count is plural. For example, the following line will create sidebars name “Foobar 1″ and “Foobar 2″:

    register_sidebars(2, array(‘name’=>’Foobar %d’));

    Creates the sidebar1, sidebar2 or Foobar1, Foobar2.

    How can I make Foobar2 = Homepage
    and Foobar3= Pages?

    Thread Starter perywinkle

    (@perywinkle)

    Whoops this is the code that worked; ie created sidebar1, sidebar2, sidebar3:

    <? php
    if ( function_exists('register_sidebar') )
    register_sidebars(3, array('name'=>'Sidebar %d'));
    ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    If you want to register several sidebars all at once, then you got it right by using that function. But if you want to do them separately, in order to give them more useful names, do something like this:

    register_sidebar(array('name'=>'Left Sidebar'));
    register_sidebar(array('name'=>'Right Sidebar'));

    And so on. Note that I’m using register_sidebar() for these. No trailing “s”.

    i’m using the plugin on a couple of sites, and i’m going to have to double check tommarow, ’cause i’m getting tired, but i think the way i did it was to use the register_sidebars(etc function instead of multiple register_sidebar functions.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    chradil: Yes, you can use register_sidebars() to create multiple sidebars at once, but if you want to make them with unique names (instead of Sidebar 1, Sidebar 2, etc), then you have to use the register_sidebar function to create each one. It does the same basic thing either way. All the register_sidebars() function does is to fill in that %d with a number and then call register_sidebar() however many times you want.

    Same thing applies if you want to use different setup parameters for each sidebar. Maybe one uses divs and the other uses ul-li’s, perhaps. Anyway, I’m using the above code for left and right sidebar creation, and it works great.

    BTW, the “register_sidebars(1, whatever);” should work if you call it multiple times as well. It’s a bit longer to execute, and you’ll get a “1” after each sidebar name, but it should actually work okay.

    Thread Starter perywinkle

    (@perywinkle)

    Yes! That worked for me!

    Here’s what I placed in the functions.php file:

    <? php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'Home'));
    register_sidebar(array('name'=>'Sidebar'));
    register_sidebar(array('name'=>'Pages'));
    ?>

    Thanks for your help!

    I should mention that I had a small issue but that was because my sidebar needed to be named…

    < ?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar') ) : ?>

    rather than:

    <? php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    Thanks!!
    pwinkz

    Thread Starter perywinkle

    (@perywinkle)

    Update: I’ve ran into some trouble with the above code. When I delete all the widgets from the sidebar or on a fresh install of WP, with out the widgets plugin working. I run into problems


    Fatal error: Call to undefined function: register_sidebars() in /home/user/public_html/wp-content/themes/tres/functions.php on line 4

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Your PHP is wrong.

    Look at this:
    <? php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'Home'));
    register_sidebar(array('name'=>'Sidebar'));
    register_sidebar(array('name'=>'Pages'));
    ?>

    To make it work even without widgets, change it to this:
    <? php
    if ( function_exists('register_sidebar') )
    {
    register_sidebar(array('name'=>'Home'));
    register_sidebar(array('name'=>'Sidebar'));
    register_sidebar(array('name'=>'Pages'));
    }
    ?>

    Thread Starter perywinkle

    (@perywinkle)

    Thanks alot! Otto

    I’m having a similar problem and I’m stuck on the solution. I was working on widgetizing a theme using a separate sidebar file while the original un-widgetized sidebar was still active. I had the thing set up exactly as I wanted when I realized theat I might want to try setting up different widgetized sidebars for the category and the pages, so I used the code from Automattic for setting up multiple widgetized sidebars:

    use register_sidebars(n) where n is the number of sidebars. Then place the appropriate number in the dynamic_sidebar() function, starting with 1.

    As soon as I uploaded the changed functions.php file, I got this error in the admin area and on the public side:

    Parse error: parse error, unexpected T_STRING in /home/icahd2/public_html/wp-content/themes/audyasha/functions.php on line 1

    So I removed the changed code and uploaded the (reverted to original) files and I still get the same error even on pages where the widgetized sidebar isn’t called. So I tried some of the suggestions here in this thread and it’s a no-go.

    What in god’s name did I do? I had it setup just fine and then I had to go and experiment with it some more.

    Any help is greatly appreciated.

    dave

    @dave: Most likely you have an extra space between “?” and “php”. There should be none.

    <? php = wrong
    <?php = correct

    Hope this helps!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Widgetizing Theme: Multiple sidebars?’ is closed to new replies.