WordPress.org

Forums

dynamic_sidebar() function without call (3 posts)

  1. Kwayy Infotech
    Member
    Posted 4 years ago #

    Hello,

    I am using Widget Logic plugin to show/hide widgets according to my site pages.

    I want to create logic like If there is no widget than there is no widget wrapper in content.

    Example:

    $the_sidebars = wp_get_sidebars_widgets();
    $featured     = count( $the_sidebars['featured-widget-area'] );
    $featured2    = count( $the_sidebars['featured2-widget-area'] );
    
    if( $featured>0 && $featured2>0 ){
    echo '<div id="featured-widget-wrapper">';
    dynamic_sidebar( 'featured-widget-area' );
    dynamic_sidebar( 'featured2-widget-area' );
    echo '</div>';
    }

    The problem is that the $featured variable is always with all widgets that are currently set, but I need only widgets that are available for current post/page. (I am disabling widgets with Widget Logic plugin.)

    I think I need to check output of a sidebar but I don't know the function. the dynamic_sidebar() always calls and print widgets. So is there any function which works same as dynamic_sidebar() except call and print the widgets?

    Thanks
    Bimal

  2. check the code of sidebar-footer.php of Twenty Ten;
    or is_active_sidebar() http://codex.wordpress.org/Function_Reference/is_active_sidebar

  3. ferahl
    Member
    Posted 3 years ago #

    // Get the sidebars contents
    $widget_sidebars_content = array();
    foreach($widget_sidebars_names as $sidebar_name)
    {
    	ob_start();
    	dynamic_sidebar($sidebar_name);
    	array_push($widget_sidebars_content, ob_get_clean());
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.