<?php
$page_layout = is_author() ? glamer_options('glamer_authors_layout') : (is_archive() ? glamer_options('glamer_archive_layout') : (is_search() ? glamer_options('glamer_search_layout') :
    glamer_options('glamer_blog_layout')));

$grid_col = is_author() ? glamer_options('glamer_author_grid_columns', 4) : (is_archive() ? glamer_options('glamer_archive_grid_columns', 4) : (is_search() ? glamer_options('glamer_search_grid_columns', 4) :
    glamer_options('glamer_grid_columns', 4)));

// Set column size based on the layout
$col_overwright = isset($_GET['col']) ? sanitize_text_field($_GET['col']) : $grid_col;
?>
<div class="single-post-item grid-style-two grid-post-item col-lg-<?php echo esc_attr($col_overwright); ?>">
    <article id="post-<?php the_ID(); ?>" <?php post_class('blog-post-card-v3'); ?>>
        <div class="blog-card-img <?php echo esc_attr(has_post_thumbnail() ? '' : 'no-thum'); ?>">
            <?php
            if (get_post_format() === 'gallery') {
                get_template_part('template-parts/post/post-format/post-format-gallery');
            } else if (get_post_format() === 'video') {
                get_template_part('template-parts/post/post-format/post-format-video');
            } else if (get_post_format() === 'audio') {
                get_template_part('template-parts/post/post-format/post-format-audio');
            } else {
                get_template_part('template-parts/post/post-grid/post-format-others');
            }
            ?>
            <?php
            if ('post' === get_post_type()) {
                if (glamer_options('glamer_show_category', true)) {
            ?>
                    <span class="blog-tag"><?php glamer_post_first_category(); ?></span>
            <?php
                }
            } ?>
        </div>
        <div class="blog-post-card-content-wrap">
            <div class="post-meta">
                <ul>
                    <?php if (glamer_options('glamer_post_author', true)) : ?>
                        <li><?php glamer_posted_by(); ?></li>
                    <?php endif; ?>
                    <?php if (glamer_options('glamer_post_date', true)) : ?>
                        <li><?php glamer_posted_on(); ?></li>
                    <?php endif; ?>
                    <?php if (get_comments_number() && glamer_options('glamer_cmnt_number', true)) : ?>
                        <li class="comment-number"><?php glamer_comment_count(); ?></li>
                    <?php endif; ?>
                </ul>
            </div>
            <?php
            $title_length = glamer_options('glamer_blog_post_title_length');
            ?>
            <h2 class="blog-post-title underline-anim-wrap">
                <a href="<?php echo esc_url(get_the_permalink()); ?>" rel="bookmark">
                    <?php echo wp_trim_words(get_the_title(), $title_length,''); ?>
                </a>
            </h2>

            <?php if (glamer_options('glamer_show_readmore', true)) : ?>
                <a class="glamer-btn btn-to-white" href="<?php echo esc_url(get_the_permalink()); ?>">
                    <?php echo esc_html(glamer_options('glamer_blog_read_text', 'Read More')); ?>
                </a>
            <?php endif; ?>
        </div>
    </article>
</div>