<?php
$podcastin_options = podcastin_theme_options();

$blog_sec_title = $podcastin_options['blog_sec_title'];
$posts_count = $podcastin_options['blog_post_no'];

?>
<div class="blog-section section-spacing">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <?php
                    if ($blog_sec_title): ?>
                    <div class="section-headings" data-aos="fade-up" >
                        <?php    echo '<h2>' . esc_html($blog_sec_title) . '</h2>';
                            ?>
                    </div>
                <?php endif; ?>
            </div>

            <div class="col-md-12">
                <div class="blog-list">

                    <?php

                    $loop = ($posts_count<=0)?30:$posts_count;
                        $args = array(
                            'post_type' => 'post',
                            'posts_per_page' => esc_attr($loop),
                            'post_status' => 'publish',
                            'order' => 'desc',

                        );
                    
                    $loop = 1;
                     $query = new WP_Query($args);
                        if ($query->have_posts()) :
                        while ($query->have_posts()) : $query->the_post();
                            global $post;
                            $post_format = get_post_format($post->ID);
                            $post_thumbnail_id = get_post_thumbnail_id(get_the_ID());
                            $image = wp_get_attachment_image_src($post_thumbnail_id, 'podcastin-blog-thumbnail-img');
                            echo(($loop % 3 == 1 || $loop == 1) ? '<div class="row">' : '');
                            
                                ?>
                            <div class="col-md-4">
                                <article class="blog-element" data-aos="fade-up" data-aos-delay="300">
                                    <?php if ($image) :?>
                                    <div class="blog-img">
                                    <img src="<?php echo esc_url($image[0]); ?>" alt="" />
                                      </div>
                                    <?php endif; ?>

                                    <?php    
                                    $blog_year  = get_the_time('Y');
                                    $blog_month = get_the_time('m');

                                    ?>

                                  
                                    
                                    <div class="post-content">
                                    <h3 class="entry-title"><a href="<?php echo esc_url(get_the_permalink()); ?>"><?php the_title(); ?></a></h3>
  <?php echo '<div class="date"><a href="'.esc_url(get_month_link($blog_year,$blog_month)).'"><span>'.esc_html(get_the_date()).'</span></a></div>'; ?>
  <p class="post-excerpt"><?php echo wp_kses_post(podcastin_get_excerpt(get_the_ID(), 125)); ?></p>
                            
                                        </div>
                                    </article>
                            </div>
                        <?php  
                    echo(($loop % 3  == 0 && $loop != 1) ? '</div>' : '');
                        $loop++;
                    endwhile;
                        wp_reset_postdata();
                         endif; ?>
                    </div>
                </div>
                </div>

        </div>
    </div>
</div>
