<?php
/**
 * Template Name: Story
 *
 */
 ?>
<?php get_header(); ?>
 
    <div id="full-content" class="media-coverage-page">
	    <section style="background: url('<?php echo home_url(); ?>/wp-content/uploads/2018/11/media-coverage-banner-bg.jpg')no-repeat center/cover;"  class="media-banner-bg">  
	      <div class="container">
	          <h1 class="page-title-cus"><?php if(is_page(134)) { echo 'Three Longs & Three Shorts'; } else { the_title(); } ?></h1>
	      </div>
	    </section>
		
			<section class="section-padding">
				<div class="container">
					<div class="row resource-content">
						
					<!-- <ul class="clearfix w-100"> -->
						
							<?php
							    $year_check = "";
								$the_query = new WP_Query( array('posts_per_page'=>11,
								'post_type'=>'story',
								'order'=> 'DESC',
								'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
								); 
							     $cnt = 1;		
								 while ($the_query -> have_posts()) : $the_query -> the_post(); 
								 $year = "";								 


							?>
							
							<?php
								// Assign the year to a variable
								//$year = the_date('M Y', '', '', FALSE);
								$year = get_the_time('M Y');
								// If your year hasn't been echoed earlier in the loop, echo it now
								if ($year !== $year_check) {
									// Now that your year has been printed, assign it to the $year_check variable
									if($year_check == ''){
										echo "<div class='post-time'>" . $year . "</div><ul class='story-gride-layout clearfix w-100'>";
									} else {
										echo "</ul><div class='post-time'>" . $year . "</div><ul class='story-gride-layout clearfix w-100'>";								
									}
									$year_check = $year;
								}

								?>
								<li>
								<div class="media-cover-wrap story-pg">
										<div class="category-name">
											<?php
												$category = get_the_category($post->ID);
												echo $category[0]->cat_name;
											?>	
										</div>
										<p class="published">Published on <span class="publish-date"><?php the_time('d M, Y'); ?></span></p><hr/>																		
										<h2 class="blog-title-h2"><?php the_title(); ?></h2>		
										<p class="media-description"><?php echo pov_excerpt( get_the_excerpt(), '250'); ?></p>
										<a href="<?php the_permalink(); ?>" class="article-link">VIEW MORE</a>
									</div>	
								</li>
								
							
								
								<?php endwhile; ?>	
								</ul>						
							<div class="pagination-custom">
								<?php 
									$big = 999999999; // need an unlikely integer
									echo paginate_links( array(
									'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
									'format' => '?paged=%#%',
									'current' => max( 1, get_query_var('paged') ),
									'total' => $the_query->max_num_pages
									) );
									wp_reset_postdata(); 
								?>
						</div>
					</div>
				</div>
			</section>
		
			
    </div>
 <!-- Pop Message HTMl-->
	 <?php include(TEMPLATEPATH.'/includes/forms/enquiry.php'); ?>
	  <!-- Pop Message End -->
<?php get_footer(); ?>