<?php 
/**
 * Register theme sidebars
 * @package PostMagazine
*/
 
function postmagazine_widgets_init() {
	register_sidebar( array(
		'name' => esc_html__( 'Blog Right Sidebar', 'postmagazine' ),
		'id' => 'blogright',
		'description' => esc_html__( 'Right sidebar for the blog', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Blog Left Sidebar', 'postmagazine' ),
		'id' => 'blogleft',
		'description' => esc_html__( 'Left sidebar for the blog', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Page Right Sidebar', 'postmagazine' ),
		'id' => 'pageright',
		'description' => esc_html__( 'Right sidebar for pages', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Page Left Sidebar', 'postmagazine' ),
		'id' => 'pageleft',
		'description' => esc_html__( 'Left sidebar for pages', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );		
	register_sidebar( array(
		'name' => esc_html__( 'Banner', 'postmagazine' ),
		'id' => 'banner',
		'description' => esc_html__( 'For Images and Sliders.', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h1 class="widget-title">',
		'after_title' => '</h1>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Post Banner', 'postmagazine' ),
		'id' => 'post-banner',
		'description' => esc_html__( 'For Images and Sliders, but ONLY shows up on posts and pages that use the left and/or right sidebar columns.', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Breadcrumbs', 'postmagazine' ),
		'id' => 'breadcrumbs',
		'description' => esc_html__( 'For adding breadcrumb navigation if using a plugin, or you can add content here.', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title">',
		'after_title' => '</div>',
	) );
		
	register_sidebar( array(
		'name' => esc_html__( 'Content Top 1', 'postmagazine' ),
		'id' => 'contenttop1',
		'description' => esc_html__( 'Content Top 1 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Content Top 2', 'postmagazine' ),
		'id' => 'contenttop2',
		'description' => esc_html__( 'Content Top 2 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Content Top 3', 'postmagazine' ),
		'id' => 'contenttop3',
		'description' => esc_html__( 'Content Top 3 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Content Top 4', 'postmagazine' ),
		'id' => 'contenttop4',
		'description' => esc_html__( 'Content Top 4 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Content Bottom 1', 'postmagazine' ),
		'id' => 'contentbottom1',
		'description' => esc_html__( 'Content Bottom 1 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Content Bottom 2', 'postmagazine' ),
		'id' => 'contentbottom2',
		'description' => esc_html__( 'Content Bottom 2 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Content Bottom 3', 'postmagazine' ),
		'id' => 'contentbottom3',
		'description' => esc_html__( 'Content Bottom 3 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Content Bottom 4', 'postmagazine' ),
		'id' => 'contentbottom4',
		'description' => esc_html__( 'Content Bottom 4 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
		
	register_sidebar( array(
		'name' => esc_html__( 'Bottom 1', 'postmagazine' ),
		'id' => 'bottom1',
		'description' => esc_html__( 'Bottom 1 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Bottom 2', 'postmagazine' ),
		'id' => 'bottom2',
		'description' => esc_html__( 'Bottom 2 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Bottom 3', 'postmagazine' ),
		'id' => 'bottom3',
		'description' => esc_html__( 'Bottom 3 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Bottom 4', 'postmagazine' ),
		'id' => 'bottom4',
		'description' => esc_html__( 'Bottom 4 position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );	
	register_sidebar( array(
		'name' => esc_html__( 'Footer', 'postmagazine' ),
		'id' => 'footer',
		'description' => esc_html__( 'Footer position', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Featured Bottom', 'postmagazine' ),
		'id' => 'featuredbottom',
		'description' => esc_html__( 'This is a single sidebar position that stretches full width of your window just above the bottom sidebar group.', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => esc_html__( 'Call To Action', 'postmagazine' ),
		'id' => 'cta',
		'description' => esc_html__( 'For call-to-action content like newsletter sign-up, promos, etc.', 'postmagazine' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title cta-title">',
		'after_title' => '</h2>',
	) );		
	
}
add_action( 'widgets_init', 'postmagazine_widgets_init' );


// Count the number of widgets to enable resizable widgets in the content top group.
function postmagazine_content_top() {
	$count = 0;
	if ( is_active_sidebar( 'contenttop1' ) )
		$count++;
	if ( is_active_sidebar( 'contenttop2' ) )
		$count++;
	if ( is_active_sidebar( 'contenttop3' ) )
		$count++;		
	if ( is_active_sidebar( 'contenttop4' ) )
		$count++;
	$class = '';
	switch ( $count ) {
		case '1':
			$class = 'col-lg-12';
			break;
		case '2':
			$class = 'col-lg-6';
			break;
		case '3':
			$class = 'col-lg-4';
			break;
		case '4':
			$class = 'col-sm-12 col-md-6 col-lg-3';
			break;
	}
	if ( $class )
		echo 'class="' . esc_attr($class) . '"';
}
// Count the number of widgets to enable resizable widgets in the content bottom group.
function postmagazine_content_bottom() {
	$count = 0;
	if ( is_active_sidebar( 'contentbottom1' ) )
		$count++;
	if ( is_active_sidebar( 'contentbottom2' ) )
		$count++;
	if ( is_active_sidebar( 'contentbottom3' ) )
		$count++;		
	if ( is_active_sidebar( 'contentbottom4' ) )
		$count++;
	$class = '';
	switch ( $count ) {
		case '1':
			$class = 'col-lg-12';
			break;
		case '2':
			$class = 'col-lg-6';
			break;
		case '3':
			$class = 'col-lg-4';
			break;
		case '4':
			$class = 'col-sm-12 col-md-6 col-lg-3';
			break;
	}
	if ( $class )
		echo 'class="' . esc_attr($class) . '"';
}

// Count the number of widgets to enable resizable widgets in the bottom group.
function postmagazine_bottom_group() {
	$count = 0;
	if ( is_active_sidebar( 'bottom1' ) )
		$count++;
	if ( is_active_sidebar( 'bottom2' ) )
		$count++;
	if ( is_active_sidebar( 'bottom3' ) )
		$count++;		
	if ( is_active_sidebar( 'bottom4' ) )
		$count++;
	$class = '';
	switch ( $count ) {
		case '1':
			$class = 'col-lg-12';
			break;
		case '2':
			$class = 'col-lg-6';
			break;
		case '3':
			$class = 'col-lg-4';
			break;
		case '4':
			$class = 'col-sm-12 col-md-6 col-lg-3';
			break;
	}
	if ( $class )
		echo 'class="' . esc_attr($class) . '"';
}
