<?php
/**
 * Template part for displaying Blog Section
 *
 * @package spiral_lite_one_page
 */

$enable_blog_section = get_theme_mod( 'spiral-lite-one-page_ed_blog_section', true );

$blog_section_title    = get_theme_mod( 'spiral_lite_one_page_blog_section_title' );
//$blog_section_content  = get_theme_mod( 'spiral_lite_one_page_blog_section_content' );
$blog_section_view_all = get_theme_mod( 'spiral_lite_one_page_blog_section_view_all', __( 'View All Blogs', 'spiral-lite-one-page' ) );
$blog_page             = get_option( 'page_for_posts' );

$blog_subtitle = get_theme_mod( 'spiral_lite_one_page_blog_section_subtitle', __( "Our Latest News Is very Elagent", 'spiral-lite-one-page' ) );

?>
<?php if ( $blog_section_title ) : ?>
<!-- Title-->
<div class="col-lg-12">
<div class="text-center">
       <h1 class="title"><?php echo esc_html( $blog_section_title ); ?></h1>
              <div class="icon"><i class="fa fa-<?php echo esc_html( get_theme_mod( 'spiral_lite_one_page_about_section_icon', 'heart-o' ) ); ?>"></i></div>
              <?php

if ( ! empty( $blog_subtitle ) ) : ?>
  <h2 class="subtitle" style="color: #666666;"><?php echo esc_html( $blog_subtitle ); ?></h2>
<?php endif; ?>

<?php if ( ! empty( $blog_section_content ) ) :?>
    <?php echo wpautop( wp_kses_post( $blog_section_content ) ); ?>
<?php endif; ?>

</div> <!-- End Title -->
               </div> <!-- End Title -->
               <?php endif; 

// Display blog posts if the blog page is set
if ( $blog_page ) : ?>
    <div class="front-blog">
        <div class="row">
            <?php
           

            // Query for latest posts
            $blog_qry = new WP_Query( array(
                'posts_per_page'      => 3,
                'ignore_sticky_posts' => true,
              //  'category__not_in'    => $exclude_cat
            ) );

            // Loop through blog posts
            if ( $blog_qry->have_posts() ) :
                while ( $blog_qry->have_posts() ) :
                    $blog_qry->the_post(); ?>
                    
                    <div class="col-lg-4">
                        <div class="post">
                            <div class="post-hover-effect">
                                <a href="<?php the_permalink(); ?>" class="post-thumbnail">
                                    <?php if ( has_post_thumbnail() ) {
                                        the_post_thumbnail( 'spiral-lite-one-page-blog', array( 'itemprop' => 'image' ) );
                                    } ?>
                                </a>
                            </div>

                            <header class="entry-header">
                                <h2 class="entry-title">
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h2>
                            </header>

                            <div class="entry-content">
                                <?php the_excerpt(); ?>
                            </div>

                            <div class="entry-meta">
                                <span class="posted-on">
                                    <a href="<?php the_permalink(); ?>">
                                        <time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>">
                                            <?php echo esc_html( get_the_date() ); ?>
                                        </time>
                                    </a>
                                </span>
                                <?php esc_html_e( '/', 'spiral-lite-one-page' ); ?>
                                <span class="comments-link">
                                    <a href="<?php the_permalink(); ?>">
                                        <?php printf( esc_html( _nx( '%1$s Comment', '%1$s Comments', get_comments_number(), 'comments title', 'spiral-lite-one-page' ) ), number_format_i18n( get_comments_number() ) ); ?>
                                    </a>
                                </span>
                            </div>
                        </div>
                    </div>
                    
                <?php endwhile; 
                wp_reset_postdata();
            endif; ?>
        </div>

        <div class="text-center">
            <a href="<?php echo esc_url( get_permalink( $blog_page ) ); ?>" class="btn btn-contour btn-big">
                <?php echo esc_html( $blog_section_view_all ); ?>
            </a>
        </div>

    </div>
<?php endif; ?>

