WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to widgetize a second sidebar (28 posts)

  1. imasharpone
    Member
    Posted 3 years ago #

    Hello all. My site is http://www.imasharpone.com. I've got two sidebars. The right sidebar allows widgets to be added but the left sidebar doesn't, which I want to change. I've searched these forums up and down but none of what I've found quite works with this theme. The code for the left sidebar is quite different than the one for the right sidebar. I would think it should be a simple matter to copy the code for the right sidebar and make a new left sidebar with it but I'm not quite sure how.

  2. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Here is a simple tut on how to add extra sidebar to your WordPress theme

  3. imasharpone
    Member
    Posted 3 years ago #

    Thanks, but inside my functions.php, there is no number after register_sidebar. My code looks like this:

    'if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => '',
    ));
    '
    along with a bunch of other code. Do I change this code or do I add a second sidebar somewhere that this code is looking to?

  4. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Yes, so that would look like this:

    if ( function_exists('register_sidebar') ) {
    register_sidebars(1, array(
        'name' => __( 'Primary Sidebar'),
        'description'   => __( 'Area One Primary Sidebar' ),
        'before_title'  => '',
        'after_title'   => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => ''
        ) );
    
    register_sidebars(1, array(
        'name' => __( 'Secondary Sidebar'),
        'description'   => __( 'Area Two Secondary Sidebar' ),
        'before_title'  => '',
        'after_title'   => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => ''
        ) );

    After this you will open your primary sidebar and edit/add:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?>
    <?php endif; // end primary widget area ?>

    and secondary sidebar:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(2) ) : ?>
    
    <?php dynamic_sidebar(2); ?>
    
    <?php endif; // end secondary widget area ?>

    Just make sure that endif is closed properly, you will know how once you open the sidebar that is widgetized.

  5. imasharpone
    Member
    Posted 3 years ago #

    So after I update the functions.php file per the above instructions, I get thr following error:

    Parse error: syntax error, unexpected $end in D:\Hosting\7241839\html\wp-content\themes\valentine\functions.php on line 36

    Line 36 is just "?>". I'm assuming this has something to do with your comment about making sure that endif is closed properly. Most of my programming experience is with lisp which doesn't require endif statements so I'm a little lost as to what exactly I should put in there.

  6. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    It's most likely an extra one in, try removing and of course try it again please :) You may also use http://wordpress.pastebin.com and paste your functions.php in case that this doesn't work for some reason.

  7. imasharpone
    Member
    Posted 3 years ago #

    Ok, so here's what I did: I created a sidebar1.php file and put the code in for the dynamic sidebar(2) you put above. I edited the original sidebar file per your instructions above. When I put the code in my functions.php file from above, I modified it to say "register sidebar" in all three locations rather than to start the if function with "register sidebar" then the next two statements to say "register sidebars". And here's the kicker: It works fine for about two minutes, meaning I can navigate through the editors along with the different pages on my dashboard, but then I get the same error as above and have to go back to my original functions.php file.

    I'm kind of at a loss here. I don't know why it only works for two minutes (not to mention when I go to the widgets page the second sidebar doesn't show up). I didn't see an extra endif anywhere but I think that if I change my functions.php file and that crashes it and all goes back to normal when I revert, something in that code intended for my functions.php file is wrong. I could post my functions.php file if you wanted but it's completely unaltered from the way it came with the theme.

  8. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Here is the functions.php file from the theme you're using. I am using your original codes.

    sidebar.php
    (same as in Valentine theme)

    <div class="widgetbar">
    <div class="sc_menu2">
    <ul>
    <?php if ( !function_exists('dynamic_sidebar')
    	        || !dynamic_sidebar(1) ) : ?>
    <?php endif; ?>
        </ul>
    </div>
    </div>

    sidebar2.php
    (I am using the same div as the above, please change that so that fits into sidebar2.php style, just as an example)

    <div class="widgetbar">
    <div class="sc_menu2">
    <ul>
    <?php if ( !function_exists('dynamic_sidebar')
    	        || !dynamic_sidebar(2) ) : ?>
    <?php dynamic_sidebar(2); ?>
    <?php endif; ?>
        </ul>
    </div>
    </div>
  9. imasharpone
    Member
    Posted 3 years ago #

    I don't know man, I think it has to do with the functions.php file because that's the error I keep getting. It keeps pointing at the last line of the file telling me it has an unexpected $end. Here's what my functions.php file looks after I've modified it:

    '<?php

    //Custom Theme Settings

    if ( function_exists('register_sidebars') ) {
    register_sidebars(1, array(
    'name' => __( 'Primary Sidebar'),
    'description' => __( 'Area One Primary Sidebar' ),
    'before_title' => '',
    'after_title' => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => ''
    ) );

    register_sidebars(1, array(
    'name' => __( 'Secondary Sidebar'),
    'description' => __( 'Area Two Secondary Sidebar' ),
    'before_title' => '',
    'after_title' => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => ''
    ) );

    add_theme_support( 'automatic-feed-links' );

    register_nav_menus( array(
    'primary' => __( 'Primary Navigation', 'valentine' ),
    ) );

    if ( ! isset( $content_width ) ) $content_width = 640;

    if ( is_singular() ) wp_enqueue_script( "comment-reply" );

    add_theme_support( 'post-thumbnails' );

    ?>'

    I don't understand what's wrong with the last line. If you start the file with <?php you have to end it with ?>. It has to be something in those two register sidebars functions because that's the only thing I've changed from the original functions.php.

    Sorry if I'm blatently doing something wrong, web coding obviously isn't my strong point.

  10. imasharpone
    Member
    Posted 3 years ago #

    Aya! Ok, here's how I managed to make it work, sort of: I went back to that site you referenced before about adding a sidebar. I replaced the "if register_sidebars" function in my functions.php file with the one from that site. Then I added the two separate sidebar files as per your instructions above, and now when I go to the widgets page on my dashboard, both sidebars show up. But, the only problem is now they don't show up on the actual site itself. Seems I read about someone else having that problem before.

  11. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Actually they do, scroll down over the footer, they're in, but the styles are bit out of place :( Please make sure that your original <div> is in place.

    So this didn't work even with the original functions.php file from above? Only thing we did was adding in an extra sidebar, that's all. If there are no errors that means that the code is "accepted" Now, one thing that I would like to point. Your standard sidebar.php will show up automatically on your site, 2nd one that we created will show up only if you add an widget via dashboard.

    I'm bushed, had only about 3 hours of sleep, need to hit the sack asap. If this doesn't work, we can continue in the morning. It's only 12:50AM very early for me, but 3 hours are "killing" me :)

  12. imasharpone
    Member
    Posted 3 years ago #

    No sense in killing yourself buddy, I know I can't function very well on only 3 hours of sleep :(

    Ok, I can't remember at this point exactly how I figured it out but here's what I ended up putting in my functions.php file:

    'if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'sidebar1',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => '',
    ));

    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'sidebar2',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => '',
    ));
    '

    Then I added them to the index.php file. They both show up on the widgets page, and sidebar1 shows up as it had before, but sidebar2 isn't showing up, I'm supposing because I have to write into style.css where and how to display it. That's where I'm stuck.

    Oh, and on a side note, even though I've removed the sidebar.php file, it is still listed and can be edited in the editor page. Strange...

  13. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    So once you drag+drop the widget for sidebar2 it should show up, can you try that please?

  14. imasharpone
    Member
    Posted 3 years ago #

    Sorry, I meant to put that in my last post that I did add a number of widgets to sidebar 2 but it still isn't showing up. There's a whole part in style.css that is for size and placement of the first sidebar. Do we need to add another one for sidebar 2?

  15. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Yes style for 2nd sidebar is needed, however even if you don't have one in place, it would show up.

    Let's try this instead for the second one:

    <?php if ( !function_exists('dynamic_sidebar')
    	        || !dynamic_sidebar(2) ) : ?>
    <?php endif; ?>
  16. imasharpone
    Member
    Posted 3 years ago #

    That is what I have in for my 2nd sidebar. Here's my full sidebar2.php :

    '<div class="widgetbar">
    <div class="sc_menu2">

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

    </div>
    </div>
    '

  17. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    so this will load the second sidebar, however I'm seeing the same class as for your primary sidebar.php, maybe that's the issue because second one is located under sidebar1.php. Makes sense?

  18. imasharpone
    Member
    Posted 3 years ago #

    Kind of. Does that mean I should change the original sidebar to be "sc_menu1"?

  19. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    you may try :) but also widgetbar as well, in case that this one floats right, another one should left.

  20. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Just installed the Valentine theme and this seems to be working fine. And here's how, very similar to what we had above, with one exception, no creation of the actual sidebar1.php.

    Open your functions.php and make sure that we set this up as http://wordpress.pastebin.com/p6ivGTiS

    Open header.php locate:

    <ul id="sliding-navigation">
    <?php
    if ( is_page() ) {
        echo $children;
    } else {
       wp_list_categories('title_li=');
    }
    ?>
    </ul>

    and let's replace that with:

    <ul id="sliding-navigation">
    <?php if ( !function_exists('dynamic_sidebar')
    	        || !dynamic_sidebar(2) ) : ?>
    <?php endif; ?>
    </ul>

    Above that you will see:

    <?php
    if ( is_page() ) {
        echo '<h2 class="submnu">Submenu</h2>';
    } else {
       echo '<h2 class="submnu">Categories</h2>';
    }
    ?>

    you can take that out as well to remove Categories title.

    sidebar.php should have only this:

    <div class="widgetbar">
    <div class="sc_menu2">
    <ul>
    <?php if ( !function_exists('dynamic_sidebar')
    	        || !dynamic_sidebar(1) ) : ?>
    <?php endif; ?>
    
        </ul>
    </div>
    </div>

    Login to your WordPress and add your widgets for the second sidebar and change the primary sidebar the way you need.

    All set.

    The results

    PS If you want to re-style the left sidebar you can.

  21. imasharpone
    Member
    Posted 3 years ago #

    Wow, you rock man. I set it all up per your instructions and it looks great. One question though: where do I tell the left sidebar to not scroll? I know we've been through this before but under the sliding-navigation part if I set it to anything but relative the whole left sidebar disappears. The whole thing does move up and down like the right sidebar, but then if you hover over it and scroll it scrolls within the sidebar.

  22. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Not a problem. I see the left one the same way as the right sidebar, they scroll with design. I must be missing something?

  23. imasharpone
    Member
    Posted 3 years ago #

    It does, but if you hover over the the left sidebar and move the mouse the sidebar scrolls within itself. Perhaps it has a fixed height and I need to make that bigger?

  24. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    I was trying to scroll actually and you clearly said move the mouse LOL my bad definitely.

    All right so we need to do this:

    div.sc_menu_wrapper {
        height: 70%;
    }

    The height: 70%, just delete and problem solved.

    Also noticing header isn't all the way across, currently 70% and when you do that the header will kind of go to the left, instead of being centered, that's expecially on 23" display like mine.

    Make it 100%.

    .header {
        width: 100%;
    }
  25. imasharpone
    Member
    Posted 3 years ago #

    Wow man, thank you so much. Looks perfect now. I did purposely put the header at 70% because if I didn't the right sidebar ends up sitting on top of it but I'm sure I can push it down some so we don't have that problem.

    So, do you have paypal...I think I owe you :)

  26. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    I am working with WordPress since the very first beginning, however just before month ago I've joined the forum, never helped here or any other place before, never been on any WP Camps either.

    So actually I owe money to WordPress for putting the food on my table with the work I provide to my clients since late 2003.

    When and if I assist is all I need, so no worries, just don't stop using the WP and we're good ;)

    If this was all, could you please mark "resolved" from your end and feel free to come back whenever you have more questions.

    Cheers,
    Emil

  27. imasharpone
    Member
    Posted 3 years ago #

    Will do. Thanks again. And for goodness sakes, go get some sleep :)

    --Ima Sharpone

  28. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    Thanks Ima, I will, some day...;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags