How to widgetize a second sidebar
-
Hello all. My site is https://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.
-
Here is a simple tut on how to add extra sidebar to your WordPress theme
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?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.
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.
It’s most likely an extra one in, try removing and of course try it again please ?? You may also use https://wordpress.pastebin.com and paste your functions.php in case that this doesn’t work for some reason.
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.
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>
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.
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.
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 ??
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…
So once you drag+drop the widget for sidebar2 it should show up, can you try that please?
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?
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; ?>
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>
‘
- The topic ‘How to widgetize a second sidebar’ is closed to new replies.