<?php
  $taxonomy = get_queried_object();
  $current_slug  =  urldecode($taxonomy->slug);
?>
<?php get_header(); ?>
<!-- ==================start content body section=============== -->
<section id="contentbody">
  <div class="row">


    <!-- start left middlebar content -->
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <div class="row">
        <div class="">

            <h1 class="text-right"> <?php echo $taxonomy->name; ?></h1>



            <div class="listing-content">
<div class="today pull-right">   <p> آج کا اخبار</p></div>
<!-- Nav tabs -->
<ul class="nav nav-tabs pull-right" role="tablist">
<?php
$args = array (
	'post_type'              => array( 'editions' ),
	'post_status'            => array( 'publish' ),
	'order'                  => 'DESC',
	'orderby'                => 'date',
  'posts_per_page'          => 1,
  'tax_query' => array(
  		array(
  			'taxonomy' => 'regions',
  			'field'    => 'slug',
  			'terms'    => $current_slug,
  		),
  	),
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
	while ( $query->have_posts() ) {
		$query->the_post();
		// do something

    $newspaper = get_field('gallery');
    $i=1;
    foreach($newspaper as $image):
      ?>
      <li role="presentation" <?php if($i==1): ?> class="active" <?php endif; ?>><a href="#page_<?php echo $i; ?>" aria-controls="page_<?php echo $i; ?>" role="tab" data-toggle="tab"><?php echo $i; ?></a></li>

       <?php
       $i++;
    endforeach;
	}
} else {
	// no posts found
}


?>


</ul>

<div class="clearfix"></div>
<!-- Tab panes -->
<div class="tab-content">
  <?php
  $args = array (
  	'post_type'              => array( 'editions' ),
  	'post_status'            => array( 'publish' ),
  	'order'                  => 'DESC',
  	'orderby'                => 'date',
    'posts_per_page'          => 1,
    'tax_query' => array(
    		array(
    			'taxonomy' => 'regions',
    			'field'    => 'slug',
    			'terms'    => $current_slug,
    		),
    	),
  );

  // The Query
  $query = new WP_Query( $args );

  // The Loop
  if ( $query->have_posts() ) {
  	while ( $query->have_posts() ) {
  		$query->the_post();
  		// do something

      $newspaper = get_field('gallery');
      $i=1;
      foreach($newspaper as $image):
        ?>
<div role="tabpanel" class="tab-pane <?php if($i==1): ?>active<?php endif; ?>" id="page_<?php echo $i; ?>">
  <div class="newspaper">
      <img id="myimage_<?php echo $i; ?>" src="<?php echo $image['url']; ?>" alt="" />
      <?php if($i==1): ?>
      <script>
          jQuery(document).ready(function($){ //fire on DOM ready
              $('#myimage_<?php echo $i; ?>').addpowerzoom()
        })
        </script>
      <?php endif; ?>
  </div><!--container fluid-->
</div>
<?php
$i++;
endforeach;
}
} else {
// no posts found
}
wp_reset_postdata();

?>





</div>

</div>



            <div class="listing">

                <div class="row">
                  <?php
                  $args = array (
                  	'post_type'              => array( 'editions' ),
                  	'post_status'            => array( 'publish' ),
                  	'order'                  => 'DESC',
                  	'orderby'                => 'date',
                    'posts_per_page'         => 6,
                    'offset'                 => 1,
                    'tax_query' => array(
                    		array(
                    			'taxonomy' => 'regions',
                    			'field'    => 'slug',
                    			'terms'    => $current_slug,
                    		),
                    	),
                  );

                  // The Query
                  $query = new WP_Query( $args );

                  // The Loop
                  if ( $query->have_posts() ) {
                  	while ( $query->have_posts() ) {
                  		$query->the_post();
                  		// do something


                        ?>
                <div class="col-lg-2 col-sm-2">

                    <p class="text-center"><?php the_date('d-m-Y', '<h4>', '</h4>'); ?></p>
                    <a href="<?php the_permalink(); ?>" class="thumbnail">
                      <?php if(has_post_thumbnail()): ?>
                        <?php the_post_thumbnail(); ?>
                      <?php endif; ?>
                      <!-- <img src="img/newspaper1.jpg" alt=""/> -->
                    </a>

                </div><!--col lg sm 2-->
                <?php

                }
                } else {
                // no posts found
                }
                wp_reset_postdata();

                ?>



                </div>
            </div><!--listing-->

        </div>
      </div>
    </div>
    <!-- End left middlebar content -->

  </div>
</section>
<!-- ==================End content body section=============== -->
<?php get_footer(); ?>
