WordPress.org

Forums

[resolved] Widgetized sidebar not working (5 posts)

  1. Llasse
    Member
    Posted 5 years ago #

    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?

  2. Adam Harley (Kawauso)
    Member
    Posted 5 years ago #

    Reading through the Codex, there's two functions for registering sidebars.

    You're using register_sidebars, which is taking 1 and 2 as the number of sidebars to create with the details you gave. You need to use register_sidebar if you want to set two sidebars with different formatting (just drop the 1, and 2,). You could use one call of register_sidebars if you want them the same though.

  3. Llasse
    Member
    Posted 5 years ago #

    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..

  4. Adam Harley (Kawauso)
    Member
    Posted 5 years ago #

    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.

  5. Llasse
    Member
    Posted 5 years ago #

    I found my problem: I misused endif; and { } so if anyone has the same problem, check your if-loops

Topic Closed

This topic has been closed to new replies.

About this Topic