Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The question is regarding, calling the default widgets into the sidebar[s]:

So, despite the solution given in THIS THREAD, I tried a different way - Ian Stewart's borrowed solution given HERE.

It's like, declaring the following lines into functions.php, suppose I have two different sidebars in my theme:

// Preset Widgets
$preset_widgets = array (
        'primary_widget_area'  => array( 'search', 'pages', 'categories', 'archives' ),
        'secondary_widget_area'  => array( 'links', 'meta' )
);

if ( isset( $_GET['activated'] ) ) {
        update_option( 'sidebars_widgets', $preset_widgets );
}

//update_option( 'sidebars_widgets', NULL );




// Check for static widgets in widget-ready areas
function is_sidebar_active( $index ){

  global $wp_registered_sidebars;

  $widgetcolums = wp_get_sidebars_widgets();

  if ($widgetcolums[$index]) return true;

        return false;

} // end is_sidebar_active

The problem is, my theme is NOT calling the default widgets in absence of any widgets at the beginning. I can't fix it, because I can't understand the code above and obviously the process explained by Ian Stewart.

And also, can't understand the explanation regarding //update_option( 'sidebars_widgets', NULL );.

How can I fix this?

share|improve this question
    
You solution may be here –  Ravs May 23 '13 at 20:07
    
Thanks @Ravs. It is't showing any fatal error when I've changed is_sidebar_active() into is_active_sidebar() in my sidebar.php. But switching from Twenty Twelve to my theme it's not showing the defaults widgets. I emptied the widget areas first in my theme, and then tried. Any other option? –  Mayeenul Islam May 24 '13 at 2:48
    
I even used 'Theme Test Drive' plugin to see the default widget mode, it's not showing the defaults. :( –  Mayeenul Islam May 24 '13 at 2:57

1 Answer 1

I solved the issue using a fallback with PHP conditionals: in my sidebar.php I coded like the following:

<?php if( is_active_sidebar('my_sidebar') ) { ?>

        <div id="secondary" class="widget-area">
            <ul class="xoxo">
                <?php dynamic_sidebar('my_sidebar'); ?>
            </ul>
        </div><!-- #secondary .widget-area -->

<?php } else { ?>

        <div id="secondary" class="widget-area">
            <ul class="xoxo">

                <?php // Default Widget : Archives ?>
                <li id="default-widget-1" class="widget-container default-widgets">
                    <h3 class="widget-title"><?php _e( 'Archives', 'your-theme' ); ?></h3>
                    <ul>
                        <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
                    </ul>
                </li> <!-- #default-widget-1 -->

                <?php // Default Widget : Pages ?>
                <li id="default-widget-2" class="widget-container default-widgets">
                    <h3 class="widget-title"><?php _e( 'Pages', 'your-theme' ); ?></h3>
                    <ul>
                        <?php wp_list_pages('sort_column=menu_order&title_li='); ?>
                    </ul>
                </li> <!-- #default-widget-2 -->

                <?php // Default Widget : Categories ?>
                <li id="default-widget-3" class="widget-container default-widgets">
                    <h3 class="widget-title"><?php _e( 'Categories', 'your-theme' ); ?></h3>                            
                    <ul>
                        <?php wp_list_categories( 'sort_column=menu_order&title_li=' ); ?>
                    </ul>
                </li> <!-- #default-widget-3 -->

                <?php // Default Widget : Meta ?>
                <li id="default-widget-4" class="widget-container default-widgets">
                    <h3 class="widget-title"><?php _e( 'Meta', 'your-theme' ); ?></h3>                            
                    <ul>
                        <?php wp_register(); ?>
                        <li><?php wp_loginout(); ?></li>
                        <?php wp_meta(); ?>
                    </ul>
                </li> <!-- #default-widget-4 -->

            </ul> <!-- .xoxo -->

        </div><!-- #secondary .widget-area -->

<?php } //endif( is_active_sidebar ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.