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

$ed_section = get_theme_mod( 'ed_portfolio', true );
$title      = get_theme_mod( 'portfolio_title', __( 'Our Projects', 'excel-business' ) );
$sub_title  = get_theme_mod( 'portfolio_subtitle', __( 'Show your work, experiences and accomplishments here. You can customize this section from Appearance > Customize > Home Page Settings > Portfolio Section.', 'excel-business' ) );
$post_per_page = (int) get_theme_mod( 'no_of_portfolio', '6' );
$view_all      = get_theme_mod( 'portfolio_readmore', __( 'View all', 'excel-business' ) );

$args = array(
    'post_type' => 'ea_portfolio',
    'post_status' => 'publish',
    'posts_per_page' => $post_per_page
);

$qry = new WP_Query( $args );

if( $ed_section && ( $title || $sub_title || $qry->have_posts() ) ){ ?>
<section class="portfolio">
	<div class="container">
		
        <?php
            excel_business_get_section_header( $title, $sub_title );
            
            if( excel_business_is_ea_active() && $qry->have_posts() ){
                echo '<div class="grid">';
                while( $qry->have_posts() ){
                    $qry->the_post(); ?>
                    <div class="element-item web">
        				<div class="img-holder">
        					<?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() ) . '">';
                                }
                            ?>
                            <div class="text-holder">
        						<div class="table">
        							<div class="table-row">
        								<div class="table-cell">
        									<?php
                                                the_title( '<h2 class="title">', '</h2>' );
                                                the_excerpt();
                                                if( $view_all ) echo '<a href="' . esc_url( get_the_permalink() ) . '" class="btn-view">' . esc_html( $view_all ) . '</a>';
                                            ?>
        								</div>
        							</div>
        						</div>
        					</div>
        				</div>
        			</div>
                    <?php
                }
                wp_reset_postdata(); 
            echo '</div>'; 
            }
        ?>
	</div>
</section>
<?php
}