• Hello I was wondering if someone could help me out. I have a registered 2 sidebars:

    function theme_widgets_init() {
    	register_sidebar( array(
    		'name'          => __( 'Sidebar', 'themename' ),
    		'id'            => 'sidebar-1',
    		'description'   => 'Sidebar for all pages',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h1 class="widget-title">',
    		'after_title'   => '</h1>',
    	) );
    
    register_sidebar( array(
    		'name'          => __( 'Sidebartwo', 'themename' ),
    		'id'            => 'sidebar-2',
    		'description'   => 'Sidebar for specific page',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h1 class="widget-title">',
    		'after_title'   => '</h1>',
    	) );
    
    }
    add_action( 'widgets_init', 'theme_widgets_init' );

    I would like to add the second sidebar to the sidebar.php loop so that if there is nothing in the side bar it shows a few things.

    <div id="secondary" class="widget-area" role="complementary">
    		<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
    
    			<aside id="search" class="widget widget_search">
    				<?php get_search_form(); ?>
    			</aside>
    
    			<aside id="archives" class="widget">
    				<h1 class="widget-title"><?php _e( 'Archives', 'theme' ); ?></h1>
    				<ul>
    					<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    				</ul>
    			</aside>
    
    			<aside id="meta" class="widget">
    				<h1 class="widget-title"><?php _e( 'Meta', 'theme' ); ?></h1>
    				<ul>
    					<?php wp_register(); ?>
    					<li><?php wp_loginout(); ?></li>
    					<?php wp_meta(); ?>
    				</ul>
    			</aside>
    
    		<?php endif; // end sidebar widget area ?>
    	</div><!-- #secondary -->
  • The topic ‘Adding a second sidebar to sidebar.php’ is closed to new replies.