SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Sidebars issue

    I'm using register_sidebars to create multiple sidebars:

    PHP Code:
    function ec_register_sidebars() {
    register_sidebars3,
        array(
        
    'name' => 'Sidebar %d',
        
    'id' => "sidebar-$i",
        
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
        
    'after_widget' => '</li>',
        
    'before_title' => '',
        
    'after_title' => ''
        
    )
    ); 
    And this is in the theme:

    PHP Code:
    <?php if ( is_active_sidebar'Sidebar 1' ) ) : ?>
    <?php dynamic_sidebar
    'Sidebar 1' ); ?>
        <?php else : ?>
        No primary sidebar content
    <?php endif; ?>
    Three sidebars appear within the WP admin. I am able to place widgets in all three. However nothing ever shows up in the theme when I load "Sidebar 1" but "Sidebar 2" and "Sidebar 3" work fine.

    BUT I just noticed that if I check to see if Sidebar 2 or 3 are active, THEN I can display Sidebar 1:

    PHP Code:
    <?php if ( is_active_sidebar'Sidebar 2' ) ) : ?>
    <?php dynamic_sidebar
    'Sidebar 1' ); ?>
        <?php else : ?>
        No primary sidebar content
    <?php endif; ?>
    What's going on with this?

  2. #2
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any suggestions? If not can anyone tell me if there are common issues with Sidebars or even bugginess?

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    306
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    could you provide some detail as to what is required? preferably via a live link or some screenshot explaining what is happening with your current code and what should actually come up
    RecipesNext.com - recipes, kitchen queries, videos & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  4. #4
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=jaagare;5036354]could you provide some detail as to what is required? preferably via a live link or some screenshot explaining what is happening with your current code and what should actually come up[/QUOTE

    Here are the sidebars in the admin: Picture 1.png As you can see, Sidebar 1 has nothing showing even though I have saved a widget there several times. You can view a page here: http://estevancarlos.kodingen.com/ecv7/?projects=rada-2

    Also, I'm not sure what happened but none of the sidebars are working now. Here's the code for the sidebars from their respective sidebar template files:

    PHP Code:
    <div id="sidebar-primary" class="sidebar">

        <?php if ( is_active_sidebar) ) : ?>

            <?php dynamic_sidebar'sidebar-3' ); ?>

        <?php else : ?>

            <!-- Create some custom HTML or call the_widget().  It's up to you. -->
            No primary sidebar content

        <?php endif; ?>
    </div>
    <div id="sidebar-article">

        <?php if ( is_active_sidebar) ) : ?>
            <?php dynamic_sidebar'sidebar-2' ); ?>
            <?php the_tags(); ?><br />

        <?php else : ?>

            <!-- Create some custom HTML or call the_widget().  It's up to you. -->
            No primary sidebar content

        <?php endif; ?>
    </div>
    <div id="sidebar-primary">
        <?php if ( is_active_sidebar) ) : ?>

            <?php dynamic_sidebar'sidebar-1' ); ?>

        <?php else : ?>

            <!-- Create some custom HTML or call the_widget().  It's up to you. -->
            No primary sidebar content

        <?php endif; ?>

    </div>
    Last edited by Mittineague; Jan 20, 2012 at 13:57. Reason: reformatting bbcode tags

  5. #5
    SitePoint Addict
    Join Date
    Sep 2009
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apologies for the horrible formatting in the previous post.

    You can view my code here (consolidated into one text file. It's not much): http://estevancarlos.kodingen.com/ecv7/ec_code.txt
    and the URL again: http://estevancarlos.kodingen.com/ecv7/?projects=rada-2

  6. #6
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    306
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ok finally a solution.
    here is how i went about it

    first in functions.php added this code
    if ( function_exists('register_sidebar') )
    {
    register_sidebars( 3, $args );
    $args = array(
    'name' => sprintf(__('Sidebar %d'), $i ),
    'id' => 'sidebar-$i',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => '' );

    }
    this is the standard wordpress code to create multiple sidebars and will create Sidebar 1, Sidebar 2 and Sidebar 3

    Then where ever we want to show the sidebar

    add this

    <?php if ( dynamic_sidebar( 'Sidebar 1' ) ) {} else { echo 'No primary sidebar content 1'; } ?>
    <?php if ( dynamic_sidebar( 'Sidebar 2' ) ) {} else { echo 'No primary sidebar content 2'; } ?>
    <?php if ( dynamic_sidebar( 'Sidebar 3' ) ) {} else { echo 'No primary sidebar content 3'; } ?>
    hope this helps you
    RecipesNext.com - recipes, kitchen queries, videos & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  7. #7
    SitePoint Member WebMonkeyOttawa's Avatar
    Join Date
    Jan 2012
    Location
    Ottawa, ON
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For multiple sidebars, this is the code I use in functions.php:

    PHP Code:
    function register_theme_sidebars(){
        if( 
    function_exists('register_sidebar') ){
            
    register_sidebar(array(
                
    'id' => 'sidebar-1',
                
    'name' => 'Sidebar 1',
                
    'description' => 'Description for sidebar location - will appear in wp-admin area.',
                
    'before_widget' => '',
                
    'after_widget' => '',
                
    'before_title' => '',
                
    'after_title' => ''
                
    ));
            
    register_sidebar(array(
                
    'id' => 'sidebar-2',
                
    'name' => 'Sidebar 2',
                
    'description' => 'Description for sidebar location - will appear in wp-admin area.',
                
    'before_widget' => '',
                
    'after_widget' => '',
                
    'before_title' => '',
                
    'after_title' => ''
                
    ));
            
    register_sidebar(array(
                
    'id' => 'sidebar-3',
                
    'name' => 'Sidebar 3',
                
    'description' => 'Description for sidebar location - will appear in wp-admin area.',
                
    'before_widget' => '',
                
    'after_widget' => '',
                
    'before_title' => '',
                
    'after_title' => ''
                
    ));
        }
    }
    add_action('widgets_init''register_theme_sidebars'); 
    The way you did it is good. But this way you can change the settings for each sidebar - like title, description, etc.

    You can also simplify the way you display the sidebar in theme like this:

    PHP Code:
    <? if( !dynamic_sidebar('sidebar-1') ): ?>
        Sidebar 1 doesn't have any widgets. 
    <? endif; ?>
    This way you don't have to put the empty {} brackets.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •