<?php
/**
 * Blog Section
 *
 * @package Excel_Business
 */

$title         = get_theme_mod( 'blog_section_title', __( 'Latest from the blog', 'excel-business' ) );
$sub_title     = get_theme_mod( 'blog_section_content', __( 'This is a short description describing about blog section.', 'excel-business' ) );
$readmore      = get_theme_mod( 'readmore', __( 'Read More...', 'excel-business' ) );
$view_all      = get_theme_mod( 'blog_section_button_label', __( 'View all Posts', 'excel-business' ) );
$page_for_post = get_option( 'page_for_posts' );

$qry = new WP_Query( array( 
    'post_type'           => 'post',
    'post_status'         => 'publish',
    'posts_per_page'      => 3,
    'ignore_sticky_posts' => true
) );

if( $title || $sub_title || $qry->have_posts() ){?>
<section class="blog-section">
	<div class="container">
		
        <?php 
        excel_business_get_section_header( $title, $sub_title );
        
        if( $qry->have_posts() ){ ?>
            <div class="row">
    			<?php while( $qry->have_posts() ){ $qry->the_post(); ?>
                    <div class="col">
        				<article class="post">
        					
                            <div class="post-thumbnail">
        						<a href="<?php the_permalink(); ?>">
                                <?php 
                                    if( has_post_thumbnail() ){
                                        the_post_thumbnail( 'excel-business-blog' );
                                    }else{
                                        echo '<img src="' . esc_url( get_template_directory_uri() . '/images/portfolio-fall-back.jpg' ) . '" alt="' . esc_attr( get_the_title() ) . '">';
                                    }
                                ?>
                                </a>
        					</div>
        					<div class="text-holder">
        						<header class="entry-header">
        							<h3 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        							<div class="entry-meta">
        								<?php
                                            excel_business_posted_on();
                                            excel_business_byline();
                                        ?>
        							</div>
        						</header>
        						<div class="entry-content">
        							<?php the_excerpt(); ?>
        						</div>
        						<footer class="entry-footer">
        							<a href="<?php the_permalink(); ?>" class="readmore"><?php echo esc_html( $readmore ); ?></a>
        						</footer>
        					</div>
        				</article>
        			</div>
    			<?php } 
                wp_reset_postdata();
                ?>			
    		</div>
            <?php 
            if( $page_for_post && $view_all ) echo '<div class="btn-holder"><a href="' . esc_url( get_permalink( $page_for_post ) ) . '" class="btn-view">' . esc_html( $view_all ) . '</a></div>'; 
        } 
        ?>
	</div>
</section>
<?php
}