<?php
/**
 * The sidebar containing the main widget area
 *
 * @package Magazine Style
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

// when both sidebars turned on reduce col size to 3 from 4.
$sidebar_pos = get_theme_mod('magazinestyle_sidebar_position');
$postID = get_queried_object_id();
$layoutmeta = get_post_meta($postID, '_singlepost_magazinestyle', true);
$layoutmetapage = get_post_meta($postID, '_pagepost_magazinestyle', true);

$col_size = 'col-md-4'; // Default column size

if (is_single() && '' !== $layoutmeta) {
    $col_size = ('lr' === $layoutmeta) ? 'col-md-3' : 'col-md-4';
} elseif (is_page() && '' !== $layoutmetapage) {
    $col_size = ('lr' === $layoutmetapage) ? 'col-md-3' : 'col-md-4';
} elseif ('both' === $sidebar_pos) {
    $col_size = 'col-md-3';
}

?>
<div class="<?php echo $col_size; ?> widget-area" id="left-sidebar"  <?php magazinestyle_do_schema( 'sidebar' ); ?>>
<?php //dynamic_sidebar('left-sidebar'); ?>
    <?php if ( ! dynamic_sidebar( 'left-sidebar' ) ) : ?>

<aside id="search" class="widget widget_search">
    <?php get_search_form(); ?>
</aside><!-- #search -->

<aside id="archives" class="widget">
    <h3 class="widget-title"><?php _e( 'Archives', 'magazine-style' ); ?></h3>
    <ul>
        <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    </ul>
</aside><!-- #archives -->

<aside id="meta" class="widget">
    <h3 class="widget-title"><?php _e( 'Meta', 'magazine-style' ); ?></h3>
    <ul>
        <?php wp_register(); ?>
        <li><?php wp_loginout(); ?></li>
        <?php wp_meta(); ?>
    </ul>
</aside><!-- #meta -->

<?php endif; ?>
</div><!-- #left-sidebar -->

