Widgetized sidebar not working
-
Hi,
I defined two Sidebars in my functions.php:
<?php register_sidebars(1, array( 'name' => 'left-sidebar', 'id' => 'left-sidebar', 'before_widget' => '<div id="%1$s" class="%2$s widget">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); register_sidebars(2, array( 'name' => 'right-sidebar', 'id' => 'right-sidebar', 'before_widget' => '<div id="%1$s" class="%2$s widget">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); ?>However, when I call one sidebar in my sidebar.php like this:
<ul class=”sidebar”> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(2) ) : ?> <li>…</li> <?php endif ?> </ul> </div>It just returns the
<div><ul><li>...</li></ul></div>
and when using if_home(); or other conditional (PHP) tags, the entire sidebar.php is not called (as it seems to crash).It worked before with one sidebar registered alone, and did work incorrectly when I used the dynamic_sidebar() funtion without any php following, but I cannot reproduce this anymore..
HELP! please.. how do I get to know, what’s going wrong, and do you have any idea about it?
-
Reading through the Codex, there’s two functions for registering sidebars.
You’re using
register_sidebars, which is taking1and2as the number of sidebars to create with the details you gave. You need to useregister_sidebarif you want to set two sidebars with different formatting (just drop the1,and2,). You could use one call ofregister_sidebarsif you want them the same though.Same problem, when I use register_sidebar in functions.php:
<?php register_sidebar( array( 'name' => 'left-sidebar', 'id' => 'left-sidebar', 'before_widget' => '<div id="%1$s" class="%2$s widget">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); register_sidebar( array( 'name' => 'right-sidebar', 'id' => 'right-sidebar', 'before_widget' => '<div id="%1$s" class="%2$s widget">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); ?>Styling is the same for now, but will change later.. I just dont understand, why he doesn’t display the widgets, even though they’re present in the admin-panel for the sidebar-widgets..
Whoops, forgot to say, you need to change
!dynamic_sidebar(2)to!dynamic_sidebar('right-sidebar'), else it doesn’t know what you’re referencing.I found my problem: I misused endif; and { } so if anyone has the same problem, check your if-loops
The topic ‘Widgetized sidebar not working’ is closed to new replies.