<?php
/*
Theme Designed By: Meysam Hosseinkhani
Email: Meysam98@Gmail.com
Author Website: Hosseinkhani.ir
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
get_header();
global $di_data;
$content_sticky = ($di_data['side_sticky'] ? ' content-sticky' : '');
$sidebar = ($di_data['post_archive_side'] == '2' ? ' right-side' : '');
?>

<div id="primary" class="container content-area main-con">
<main id="main" class="site-main">
<?php if($di_data['show_bread']) { woocommerce_breadcrumb(); }
if ($di_data['show_head_banner']) { dina_header_banner(); }  ?>
    <div class="row prod-row<?php echo $sidebar; ?>">
        <div class="col-lg-9 col-12<?php echo $content_sticky; ?>">
       <?php global $di_data;
	if($di_data['post_col'] == 2){
		$pclasses = 'col-6';
	}
	elseif($di_data['post_col'] == 3){
		$pclasses = 'col-md-4 col-6';
	}
	elseif($di_data['post_col'] == 4){
		$pclasses = 'col-md-3 col-6';
    }
    elseif($di_data['post_col'] == 5){
		$pclasses = 'col-p-5 col-md-3 col-6';
	}
    if($di_data['mobile_single_col']) {
        $pclasses .= ' mobile-single-col';
    }
?>

<?php if ( have_posts() ) : ?>

<ul class="posts<?php if($di_data['ajax_post']){echo ' ajax_post';} ?>">
<?php while ( have_posts() ) : the_post(); ?>

<?php if(get_post_type() == 'product') { ?>
    <li class="<?php echo $pclasses; ?> mini-product-con type-product">

<?php get_template_part('includes/content-product'); ?>

</li>
<?php } elseif(get_post_type() == 'post') { ?>      
<?php $post_categories = get_post_primary_category(get_the_ID(), 'category'); 
$primary_category = $post_categories['primary_category']; ?>
<li class="mini-post-con <?php echo $pclasses; ?>"> 
    <div class="shadow-box <?php echo $di_data['prod_hover']; ?> mini-post">
        <?php $link_target = ($di_data['open_prod_new_tab'] ? '_blank' : '_self'); ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="post-link" target="<?php echo $link_target; ?>">
                <?php po_img() ?>
            <span class="post-title">
                <?php the_title(); ?>
            </span>
            <?php if ($di_data['show_post_excerpt']) { ?>
            <span class="post-exc">
                <?php echo strip_tags(get_the_excerpt()); ?>
            </span>
            <?php } ?>
            <?php if($di_data['show_post_cat']) { ?>
                <span class="post-cat">
                    <?php echo $primary_category->name; ?>
                </span>
            <?php } ?>
        </a>
        <?php if($di_data['show_hover_btns']) { ?>
        <a href="<?php the_permalink(); ?>" class="btn btn-success btn-buy<?php if( $di_data['show_hover_btns_fixed'] ) { echo ' btn-buy-fixed'; } ?>">
            <i class="fal fa-file-alt" aria-hidden="true"></i>
            <?php echo __( 'Read More...', 'dina-kala' ); ?>
        </a>
        <?php } ?>
    </div>
</li>
    <?php } else { ?>
<li class="mini-post-con <?php echo $pclasses; ?>"> 
    <div class="shadow-box <?php echo $di_data['prod_hover']; ?> mini-post">
        <?php $link_target = ($di_data['open_prod_new_tab'] ? '_blank' : '_self'); ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="post-link" target="<?php echo $link_target; ?>">
                <?php po_img() ?>
            <span class="post-title">
                <?php the_title(); ?>
            </span>
            <?php if ($di_data['show_post_excerpt']) { ?>
            <span class="post-exc">
                <?php echo strip_tags(get_the_excerpt()); ?>
            </span>
            <?php } ?>
        </a>
        <?php if($di_data['show_hover_btns']) { ?>
        <a href="<?php the_permalink(); ?>" class="btn btn-success btn-buy<?php if( $di_data['show_hover_btns_fixed'] ) { echo ' btn-buy-fixed'; } ?>">
            <i class="fal fa-file-alt" aria-hidden="true"></i>
            <?php echo __( 'Read More...', 'dina-kala' ); ?>
        </a>
        <?php } ?>
    </div>
</li>
    <?php } ?>

<?php endwhile; ?>
</ul>

<?php wp_pagination(); ?>
<?php if($di_data['ajax_post']) { ?>
<div class="col-12 load-more">
	<div class="page-load-status">
		<p class="infinite-scroll-request"><i class="fal fa-spinner-third fa-spin" aria-hidden="true"></i></p>
		<p class="infinite-scroll-last alert alert-info"><?php _e('End of content','dina-kala') ?></p>
		<p class="infinite-scroll-error alert alert-info"><?php _e('No more pages to load','dina-kala') ?></p>
	</div>
	<span id="load-more-button" class="btn btn-outline-dina"><?php _e('Load More Posts','dina-kala') ?></span>
</div>
<?php } ?>

<?php else : ?>
      <div class="alert alert-warning" role="alert">
         <strong><span class="fal fa-bell fa-lg" aria-hidden="true">
         </span> <?php _e('No posts found!','dina-kala') ?></strong>
      </div>
<?php endif; ?>
        
        </div>
        <?php get_sidebar(); ?>
    </div>
</main>

</div>
<?php 
get_footer();