<?php
function author_portfolio_before_default_page_markup() {
    global $post;
    if (is_home()) {
        $sidebar_layouts = get_theme_mod('blog_page_sidebar', 'no');
    } elseif (is_archive()) {
        $sidebar_layouts = get_theme_mod('archive_page_sidebar', 'no');
    } elseif (is_page()) {
        $get_page_sidebar_settings = get_theme_mod('page_sidebar', 'no');
        $sidebar_layouts = $get_page_sidebar_settings;
        $indvPageSidebarSettings = get_post_meta($post->ID, 'author_portfolio_sidebar-settings', true);

        if ('customizer' === $indvPageSidebarSettings || empty($indvPageSidebarSettings)) {
            $sidebar_layouts = $get_page_sidebar_settings;
        } else {
            $sidebar_layouts = $indvPageSidebarSettings;
        }
    } elseif (is_single()) {
        $get_post_sidebar_settings = get_theme_mod('post_sidebar', 'no');
        $sidebar_layouts = $get_post_sidebar_settings;
        $indvPostSidebarSettings = get_post_meta($post->ID, 'author_portfolio_sidebar-settings', true);
        if ('customizer' === $indvPostSidebarSettings || empty($indvPostSidebarSettings)) {
            $sidebar_layouts = $get_post_sidebar_settings;
        } else {
            $sidebar_layouts = $indvPostSidebarSettings;
        }
    } elseif (is_search()) {
        $sidebar_layouts = get_theme_mod('search_page_sidebar', 'no');
    }

    $blogcontent = 'col-md-12';
    if ($sidebar_layouts === 'right') {
        $blogcontent = 'col-md-7 col-lg-8 order-0';
    } elseif ($sidebar_layouts === 'left') {
        $blogcontent = 'col-md-7 col-lg-8 order-1';
    } elseif ($sidebar_layouts === 'both') {
        $blogcontent = 'col-md-6 col-lg-6 order-1'; // Adjusted for both sidebars
    } elseif ($sidebar_layouts === 'no') {
        $blogcontent = 'col-md-12';
    }

    ?>
        <div class="blog-post-section">
            <div class="container">
                <div class="row">
                    <?php if ($sidebar_layouts === 'both' || $sidebar_layouts === 'left') : ?>
                        <div class="col-md-3 col-lg-3 order-0 pl-xl-5">
	                        <aside id="left-sidebar-area" class="widget-area left-sidebar-area">
								<?php dynamic_sidebar('left-sidebar'); ?>
							</aside>
                        </div>
                    <?php endif; ?>
                    <div class="<?php echo esc_attr($blogcontent); ?>">
    <?php
}
add_action('author_portfolio_before_default_page', 'author_portfolio_before_default_page_markup');

function author_portfolio_after_default_page_markup() {
    global $post;
    if (is_home()) {
        $sidebar_layouts = get_theme_mod('blog_page_sidebar', 'no');
    } elseif (is_archive()) {
        $sidebar_layouts = get_theme_mod('archive_page_sidebar', 'no');
    } elseif (is_page()) {
        $get_page_sidebar_settings = get_theme_mod('page_sidebar', 'no');
        $sidebar_layouts = $get_page_sidebar_settings;
        $indvPageSidebarSettings = get_post_meta($post->ID, 'author_portfolio_sidebar-settings', true);
        if ('customizer' === $indvPageSidebarSettings || empty($indvPageSidebarSettings)) {
            $sidebar_layouts = $get_page_sidebar_settings;
        } else {
            $sidebar_layouts = $indvPageSidebarSettings;
        }
    } elseif (is_single()) {
        $get_post_sidebar_settings = get_theme_mod('post_sidebar', 'no');
        $sidebar_layouts = $get_post_sidebar_settings;
        $indvPostSidebarSettings = get_post_meta($post->ID, 'author_portfolio_sidebar-settings', true);
        if ('customizer' === $indvPostSidebarSettings || empty($indvPostSidebarSettings)) {
            $sidebar_layouts = $get_post_sidebar_settings;
        } else {
            $sidebar_layouts = $indvPostSidebarSettings;
        }
    } elseif (is_search()) {
        $sidebar_layouts = get_theme_mod('search_page_sidebar', 'no');
    }

    $blogsidebar = 'col-md-5 col-lg-4 order-1 pl-xl-5';
    $sidebarshow = false;
    if ($sidebar_layouts === 'right') {
        $blogsidebar = 'col-md-5 col-lg-4 order-1 pl-xl-5';
        $sidebarshow = true;
    } elseif ($sidebar_layouts === 'left') {
        $blogsidebar = 'col-md-5 col-lg-4 order-0 pl-xl-5';
        $sidebarshow = true;
    } elseif ($sidebar_layouts === 'both') {
        $blogsidebar = 'col-md-3 col-lg-3 order-2 pl-xl-5'; // Right sidebar for 'both'
        $sidebarshow = true;
    } elseif ($sidebar_layouts === 'no') {
        $blogsidebar = 'sidebar-hide';
        $sidebarshow = false;
    }

    ?>
                    </div>
                    <?php if ($sidebar_layouts === 'both' || $sidebar_layouts === 'right') : ?>
                        <div class="<?php echo esc_attr($blogsidebar); ?>">
                            <?php get_sidebar(); // Assumes a 'right' sidebar is registered ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    <?php
}
add_action('author_portfolio_after_default_page', 'author_portfolio_after_default_page_markup');