<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Sparta
 */
$grid_columns = get_theme_mod('sparta_blog_list_grid_columns');

$class_wap_article = '';
$colunms_post = get_query_var('colunms_post');

if (isset($colunms_post) && $colunms_post != ''):
    switch ($colunms_post) {
        case '1':
            $class_wap_article = 'col-lg-12';
            break;
        case '2':
            $class_wap_article = 'col-lg-6';
            break;
        case '3':
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-4';
            break;
        case '4':
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-3';
            break;
        default :
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-4';
    }
else :
    switch ($grid_columns) {
        case '1':
            $class_wap_article = 'col-lg-12';
            break;
        case '2':
            $class_wap_article = 'col-lg-6';
            break;
        case '3':
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-4';
            break;
        case '4':
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-3';
            break;
        default :
            $class_wap_article = 'col-lg-6 col-md-6 col-xl-4';
    }

endif;
?>
<div class="blog-item <?php echo esc_html($class_wap_article); ?>">
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="entry-content">
            <?php
            if (has_post_thumbnail()) :
                echo '<div class="post-thumbnail">';
                if ($grid_columns == '1'):
                    echo '<a href="' . esc_url(get_permalink()) . '">';
                    the_post_thumbnail();
                    echo '</a>';
                else :
                    echo '<a href="' . esc_url(get_permalink()) . '">';
                    the_post_thumbnail('sparta-blog-thumb');
                    echo '</a>';
                endif;
                ?>
                <ul class="post-meta">
                    <li class="meta-reading-time">
                        <?php
                        if (!post_password_required() && (comments_open() || get_comments_number())) :
                            echo wp_kses(__(' <i class="fa fa-comment"></i> ', 'sparta'), array('i' => array('class' => array())));
                            comments_popup_link(esc_html__('0', 'sparta'), esc_html__('1', 'sparta'), esc_html__('%', 'sparta'));
                        endif;
                        ?>
                    </li>
                </ul>
                <?php
                echo '</div>';
            endif;
            ?>
            <div class="sparta-blog-info <?php if (has_post_thumbnail()) : echo 'lst-with-thumb'; endif; ?>">
                <?php
                if ('post' === get_post_type()) : ?>
                    <div class="entry-meta post-meta heading3">
                        <?php Sparta_Helper::sparta_posted_meta(); ?>
                    </div>
                <?php
                endif;
                if (is_single()) :
                    the_title('<h1 class="entry-title">', '</h1>');
                else :
                    the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
                endif;

                if (has_excerpt()):
                    $sparta_blog_list_excerpt_length = get_theme_mod('sparta_blog_list_excerpt_length', '15');

                    echo '<div class="entry-excerpt heading3">';
                    echo wp_trim_words(get_the_excerpt(), $sparta_blog_list_excerpt_length, '...');
                    echo '</div>';
                endif;
                ?>
                <a href="<?php the_permalink(); ?>"
                   class="read-more secondary_btn"><span><?php echo esc_html__('Read more', 'sparta'); ?></span>
                </a>
            </div>
        </div>
    </article><!-- #post-## -->
</div>

