<?php
$life_coaches_options = life_coaches_theme_options();

$blog_sec_title = $life_coaches_options['blog_sec_title'];
$blog_cursive_title = $life_coaches_options['blog_cursive_title'];
$posts_count = $life_coaches_options['blog_post_no'];

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

                            <?php    echo '<h2>' . esc_html($blog_sec_title) . '</h2>';
                                ?>
                        
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <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, 'life-coaches-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">
                                    <a href="<?php the_permalink(); ?>"> <img src="<?php echo esc_url($image[0]); ?>" alt="" /></a>
                                      </div>
                                    <?php endif; ?>


                                  
                                    
                                    <div class="post-content">
                                    <h3 class="entry-title"><a href="<?php echo esc_url(get_the_permalink()); ?>"><?php the_title(); ?></a></h3>
                            <a href="<?php the_permalink(); ?>" class="blog-read-more"><?php _e('Read More','life-coaches'); ?></a>
                                        </div>
                                    </article>
                            </div>
                        <?php  
                    echo(($loop % 3  == 0 && $loop != 1) ? '</div>' : '');
                        $loop++;
                    endwhile;
                        wp_reset_postdata();
                         endif; ?>
                 
                </div>
            </div>
        </div>
    </div>
</div>
