<?php global $qaleb;?>
<?php
function map_post_ajax(){
    $offset = $_POST["offset"];
    $ppp = $_POST["ppp"];
    $cat = $_POST["cat"];
    header("Content-Type: text/html");
	if($cat!=null){
?>
<div class="title"> <h2><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo get_cat_name($cat); ?></h2>
  <div class="dropmap">
  <button class="mapbtn">نمایش بر اساس <i class="fa fa-angle-down" aria-hidden="true"></i></button>
  <div class="dropmap-content">
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">نقشه</a>
	<a class="openbtn" onclick="openNav()">لیست</a>
  </div>
</div> 
</div>
<div class="posts">
  <?php
    $args = array(
        'post_type' => 'post',
		'posts_per_page'=> '3',
		'cat'	=>	$cat,
    );

    $loop = new WP_Query($args);
	
    while ($loop->have_posts()) { $loop->the_post(); 
	?>
<section class="apnews ne_map">
<div class="polist clearfix">
<div class="item clearfix">
<div class="datee"><span><?php the_time('d');  ?></span><b><?php the_time('F');  ?></b></div>
<div class="thumbnail">
<?php if(has_post_thumbnail()){?>
<a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url('loop-bar'); ?>" alt="<?php the_title(); ?>"></a>
<?php }else{ ?>
<img src="<?php bloginfo("template_url"); ?>/img/none.png">
<?php } ?>
</div>
<div class="det">
<div class="met">
<?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?><span class="cat"><?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></span> <?php } ?>
</div>
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<p><?php if(get_meta('lead') != false) : echo get_meta('lead'); else : the_excerpt(); endif; ?> </p>
</div>
</div>
</div>
</section>
  <?php
    }
?>
<div class="m-more"> <a href="<?php echo get_category_link( $cat ); ?>"> نمایش همه <i class="fa fa-long-arrow-left" aria-hidden="true"></i></a> </div> 
</div>
<?php
	}else{
		?>
        <h2>...</h2> 
<div class="posts foot">
	<p>مطلبی در مورد این استان یافت نشد!</p>
</div>
        <?php
	}
    exit; 

}

add_action('wp_ajax_nopriv_map_post_ajax', 'map_post_ajax'); 
add_action('wp_ajax_map_post_ajax', 'map_post_ajax');