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

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

if ( ! is_active_sidebar( 'left-sidebar' ) ) {
	return;
}

// when both sidebars turned on reduce col size to 3 from 4.
$sidebar_pos = get_theme_mod('digital_sidebar_position');
$postID = get_queried_object_id();
$layoutmeta = get_post_meta($postID, '_singlepost_digital', true);
$layoutmetapage = get_post_meta($postID, '_pagepost_digital', 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 digital_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', 'digital' ); ?></h3>
    <ul>
        <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    </ul>
</aside><!-- #archives -->

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

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

