WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Sidebars Not Working (10 posts)

  1. skoskie
    Member
    Posted 4 years ago #

    Hi,

    My site has a multitude of sidebars that are not intuitively named. I'm attempting to resolve this by editing name in the register sidebar function; the get_sidebar('Sidebar Name') function in the index.php file; and the dynamic_sidebar ('Sidebar Name') function in the sidebar file.

    This works perfectly in the admin area, where the new names now appear and have widgets associated with them, but in the index.php file where I am calling them, it fails. This is not an alignment issue -- there is no html output to be found.

    I can provide code if necessary. Any help would be greatly appreciated.

    Thanks,
    Shelton

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Are you using register_sidebar or register_sidebars? There's a big difference. You should be using the latter with multiple sidebars.

  3. skoskie
    Member
    Posted 4 years ago #

    Great question. I wasn't aware of the plural form of that function... I've been using several 'singulars'. But I think that is what I want given by objective of having intuitive sidebar names. From the page you linked to...

    The only times you might need to call this function instead of register_sidebars() are when you want to give unique names to sidebars, such as “Right Sidebar” and “Left Sidebar”

    Here is how I've registered the sidebars...

    register_sidebar(array(
    		'name' => 'Default Right Sidebar',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>'
    	));	
    
    	register_sidebar(array(
    		'name' => 'Homepage Column 1',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h1>',
    		'after_title' => '</h1>'
    	));
  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    OK - that code looks fine to me. What's in your sidebar files?

  5. skoskie
    Member
    Posted 4 years ago #

    It's a pretty straight forward call:

    <?php get_sidebar('homepage-column-1'); ?>

    ... which contains ...

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage Column 1') ) : ?>
    
    <!-- dynamic_sidebar("Homepage Column 1") has failed -->
    
    <?php endif; ?>
  6. skoskie
    Member
    Posted 4 years ago #

    What's funny is that if I just include the contents of the sidebar-homepage-column-1.php file it works just fine. Should I just delete the file and put a call to the dynamic sidebar in my index.php file.

    Should I be using dynamic_sidebar instead of get_sidebar??

  7. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    I hate to ask the obvious but do you have widgets installed in Homepage Column 1?

  8. skoskie
    Member
    Posted 4 years ago #

    Ha. It's a fair question, but yes I do.

  9. skoskie
    Member
    Posted 4 years ago #

    I think I realized what I've done. I assumed that get_sidebar could call the name of the sidebar, rather than the name of the file. I had treated the file name as if it didn't matter.

    But that begs the question, should the file name matter? Why would I use get_sidebar when I could just use dynamic_sidebar instead?

    Thanks for your help.

  10. skoskie
    Member
    Posted 4 years ago #

    I have to state that the reason for this confusion ... and now the cause for even more confusion is that this bit of code works just fine:

    <?php get_sidebar('Homepage Column 4'); ?>

    ...and there is no file by that name (sidebar-.....php).

Topic Closed

This topic has been closed to new replies.

About this Topic