<?php
/**
 * @package Maskitto Light
 */

$gallery = get_post_meta( get_the_ID(), 'wpcf-image');
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <div class="blog-item-container">

        <div class="blog-top blog-top-large">
            <a href="<?php echo esc_url( get_permalink() ); ?>" class="blog-title"><?php the_title(); ?><?php echo maskitto_light_admin_edit(get_the_ID()); ?></a>

            <div class="row">
                <div class="col-md-6">
		            <div class="blog-details">
		                <span><?php echo the_date(); ?></span>
		                <span>By <?php echo get_the_author(); ?></span>
		            </div>
		        </div>
                <div class="col-md-6 text-right">
                    <a href="#"><i class="fa fa-comment-o"></i> | <?php comments_number( '0', '1', '%' ); ?></a>
                </div>
            </div>
        </div>

        <?php if ( has_post_thumbnail() ) : ?>
            <div class="blog-media">
                <?php echo the_post_thumbnail(); ?>

                <?php 
                    $cat = get_the_category();
                    if( $cat[0]->name ) :
                ?>
                    <a href="<?php echo get_category_link( get_cat_ID( $cat[0]->name ) ); ?>" class="blog-category"><?php echo $cat[0]->name; ?></a>
                <?php endif; ?>
            </div>
        <?php endif; ?>
       
        <div class="blog-bottom blog-bottom-large">
            <div class="blog-content">
                <?php if ( !has_post_thumbnail() ) {
                    $cat = get_the_category();
                    if( isset( $cat[0] ) && $cat[0]->name ){
                ?>
                    <a href="<?php echo get_category_link( get_cat_ID( $cat[0]->name ) ); ?>" class="blog-category blog-category-right"><?php echo $cat[0]->name; ?></a>
                <?php } } ?>
                <div class="post-inner"><?php the_content(); ?></div>
            </div>
        </div>

        <?php 
        $gallery_count = 0;
        if( isset( $gallery ) ) :
            foreach($gallery as $media) :
                if( $media ) :
                    $gallery_count++;
                endif;
            endforeach;
        endif;

        if( $gallery_count > 0) : ?>
        <div class="blog-bottom blog-bottom-large post-gallery">
            <div class="post-gallery-title"><?php _e( 'Gallery', 'maskitto-light' ); ?></div>
            <div class="post-gallery-list group">
                <?php foreach($gallery as $media) : ?>
                    <a href="<?php echo $media; ?>" class="post-gallery-item" style="background-image:url(<?php echo $media; ?>);"></a>
                <?php endforeach; ?>
            </div>
        </div>
        <?php endif; ?>
    </div>
</article>