WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Sidebars
[resolved] Bugs in method dynamic_sidebar() (12 posts)

  1. JochenT
    Member
    Posted 2 years ago #

    Hi,

    Me again. I've found two bugs in method dynamic_sidebar() in code fragment

    $sidebars = explode(",", $sidebars);
    if(!$sidebars){
    	$sidebars = "multiple-sidebars-default";
    }
    foreach ($sidebars as $sidebar) {
    	if (is_active_sidebar($sidebar)) {
    		dynamic_sidebar($sidebar);
    	}
    }

    One problem is the use of the function explode(). If $sidebars is an empty string it returns an none empty array which contains one empty element (count($sidebars)==1). Thus the following if-statement if(!$sidebars) { ... } will always fail as the array is not empty. Finally the foreach (...) will loop and call function 'is_active_sidebar($sidebar)` with an empty string. This will always fail and the default sidebar is never displayed as fallback.

    The second problem is the definition of the array for the name of the default sidebar $sidebars = "multiple-sidebars-default";. The assignment of a string to a variable is not an array. You have to cast the string into an array before assignment $sidebars = array("multiple-sidebars-default");. But as this statement was never executed it had no effect on the code.

    Together with my suggestion from the other post the modified code could be

    $sidebars = empty($sidebars) ? array('multiple-sidebars-default') : explode(',', $sidebars);
    foreach ($sidebars as $sidebar) {
    	if (is_active_sidebar($sidebar)) {
    		$success = dynamic_sidebar($sidebar) ? true : $success;
    	}
    }

    http://wordpress.org/extend/plugins/multiple-sidebars/

  2. Andrico
    Member
    Plugin Author

    Posted 2 years ago #

    perfect!
    and is implemented as I said!

    very good correction!

    I will put you among the contributors!

    Sorry for the English, but use the google translator.

  3. JochenT
    Member
    Posted 2 years ago #

    Hi,

    Thank you. This is much of honor. The good idea and most of the code is still from you. But I appreciate it.

  4. trulygood
    Member
    Posted 1 year ago #

    Hi I am attempting to use this Plugin/this code but despite having created the Sidebars, activated them, and assigning them to a page, nothing is being displayed.

    Here is my sidebar template code:

    <?php
    
    	$sidebars = empty($sidebars) ? array('multiple-sidebars-default') : explode(',', $sidebars);
    foreach ($sidebars as $sidebar) {
    	if (is_active_sidebar($sidebar)) {
    		$success = dynamic_sidebar($sidebar) ? true : $success;
    	}
    } ?>

    Am I missing something?

    Cheers,
    Andy

  5. JochenT
    Member
    Posted 1 year ago #

    These changes are only for function dynamic_sidebar() in the plugin code. In the current version of the plugin these changes are already implemented. You have to do nothing if you use the latest version.

  6. trulygood
    Member
    Posted 1 year ago #

    I see. Well, doing nothing also did not work.

    I tried to activate the sidebars using the Widget and that did nothing. I also tried to put the sidebar code as seen in the screenshot here (http://s.wordpress.org/extend/plugins/multiple-sidebars/screenshot-3.jpg?r=548482), but that did not work.

    What is the best way to get the Custom Sidebars I have created and activated to show up in my theme?

  7. JochenT
    Member
    Posted 1 year ago #

    I use it in TwentyEleven the following way:

    <?php
    global $MultipleSidebars; // from plugin "Multiple Sidebars"
    $useFallbackSidebar = true;
    if ( method_exists( $MultipleSidebars, 'dynamic_sidebar' ) ) {
        if ($MultipleSidebars->dynamic_sidebar()) {
            $useFallbackSidebar = false;
        }
    }
    ?>
    <?php if ($useFallbackSidebar && !dynamic_sidebar('sidebar-1')) : // use wp core sidebar functions ?>
    
      // any basic fallback sidebar widgets
    
    <?php endif; ?>

    See sidebar.php in theme TwentyEleven for details.

  8. trulygood
    Member
    Posted 1 year ago #

    Hi JochenT.
    Thanks for the reply, I appreciate it.

    I am using a child theme for TwentyTen theme. I tried your code as is, but it did not work.

    I then modified it so it used TwentyTen code, but that is not working either. I can typically figure out things like these, so this is frustrating.

    Here is the code I am trying...

    <?php
    global $MultipleSidebars; // from plugin "Multiple Sidebars"
    $useFallbackSidebar = true;
    if ( method_exists( $MultipleSidebars, 'primary-widget-area' ) ) {
        if ($MultipleSidebars->primary-widget-area()) {
            $useFallbackSidebar = false;
        }
    }
    ?>
    <?php if ($useFallbackSidebar &&! dynamic_sidebar( 'primary-widget-area')) : // use wp core sidebar functions ?>
    
      // any basic fallback sidebar widgets
    
    <?php endif; ?>

    Which is returning NOTHING at all, not even the "any basic fallback sidebar widgets" text

    I have the MultipleSidebar widget placed in my Primary Sidebar, and my "Default Sidebar".

    Any thoughts?

  9. JochenT
    Member
    Posted 1 year ago #

    Sorry, you need knowledge in PHP to understand this. Perhaps you may ask a friend to help you.

  10. trulygood
    Member
    Posted 1 year ago #

    Hmmm..
    Is there no way to have the Plugin just work? Most Plugins I've ever used work upon Activation. Sometimes I have to drop a line or 2 of code into a template file. But I have never needed thorough php knowledge to make a Plugin work according to its default behaviour. That is why i am confused. I don't think I am attempting to make the Plugin respond to any custom behaviour at all.

    Let's take it a step backwards.
    -I install and Activate the Plugin.
    -I create a custom Sidebar.
    -I activate the custom Sidebar in the Sidebars > Options menu
    -I assign it to a specific page by dragging it from Inactive to Active in that page screen
    -I drop the Multiple Sidebars Widget into my Primary Widget Area

    Shouldn't the custom Sidebar I created now be displayed on the Page I assigned it to? This is why I am confused. I follow basic instructions accordingly, but no Sidebar is displayed.

    Any thoughts? Perhaps Plugin developer would know?

  11. Andrico
    Member
    Plugin Author

    Posted 1 year ago #

    Hello, trulygood!

    It seems very strange that the plugin does not work that way.

    I would say that you first uninstall the plugin, and follow the steps I mention below:

    1 - install the plugin
    2 - Activate the plugin
    3 - place the widget "Multiple Sidebars" in the default template sidebar
    4 - create a page, post or custom post type, and from the menu on the right side, create a sidebar and place in the sector "active".

    I tried it and it worked. You might have a conflict with another plugin.

    Sorry for the delay in answering, and for my English. I use google translate. ;)

    If the above does not work, follow the steps 1, 2, 4, and places in the area, removing all the template code that references dynamic_sidebar. (or override it with " /* OLD CODE */ "). and put in its place

    <?php

    global $MultipleSidebars;
    if ($MultipleSidebars -> dynamic_sidebar ()) {
    echo "No sidebars selected";
    }

    ?>

    Good luck and hope it works and you solve a problem!

  12. trulygood
    Member
    Posted 1 year ago #

    Hi Andrico,
    Thanks very much for the response. I try both your suggestions, and no results.
    There are no other Plugins installed and activated.

    I tried with custom TwentyTen Child Theme, as well as TwentyTen itself. I even gave TwentyEleven a shot, no luck.

    Perhaps you can take a look?

    andy@trulygood.com

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic