<?php
/*
Template Name: News-list
*/

$page = get_page(get_the_ID());
$currentlang = pll_current_language();
get_header();
$years = array();
$defaultYr = 0;
$args = array(
	'offset'           => 0,
	'category'         => 15,
	'orderby'          => 'post_date',
	'order'            => 'DESC',
	'post_type'        => 'post',
	'post_status'      => 'publish',
	'lang' => 'eng',
	//^^^^^^^^^^^^^^-------------------------------
	'suppress_filters' => true,
	'posts_per_page' => '99999999'
); 
$postsBY = get_posts($args);

foreach($postsBY as $postBY) {
	$pYr = date('Y', strtotime($postBY->post_date));
	if($pYr>$defaultYr){
		$defaultYr = $pYr;
	}
	$years[$pYr][] = $postBY;
}
krsort($years);
if(isset($_REQUEST['postyear']) || isset($_REQUEST['gads'])){
	$yearz = isset($_REQUEST['postyear'])?$_REQUEST['postyear']:$_REQUEST['gads'];
}else{
	$yearz = $defaultYr;
}
?>
<div class="con">
	<div class="col side-row">
		<div class="round-block" style="background-image:url(img/services.png)">
			<span class="middle"><?=get_the_title(($currentlang=='eng'?'401':'403'))?></span>
		</div>
		<nav class="side-menu">
			<ul>
				<?
				foreach($years AS $ga=>$po){
				?>
					<li><a <?=$yearz==$ga?'class="active"':''?> href="<?=get_permalink(($currentlang=='eng'?'401':'403'))?>?<?=$currentlang=='eng'?'postyear':'gads'?>=<?=$ga?>"><?=$ga?></a></li>
				<?}?>
			</ul>
		</nav>
	</div>
	<div class="col middle-row widerow">
		<ul class="newsthumbs">
			<?
			foreach($years[$yearz] AS $post){
			?>
				<li >
					<a href="<?=the_field('links', $post->ID)?>" target="_BLANK">
						<img src="<?=the_field('image_', $post->ID)?>" />
						<?/*
						<h3><?=wp_trim_words($post->post_title, 50)?></h3>
						<span class="date"><?=date('j.m.Y', strtotime($post->post_date))?></span>
						<p><?=wp_trim_words($post->post_content, 25)?></p>
						*/?>
					</a>
				</li>
				
			<?}?>
		</ul>
	</div>
</div>
<?php get_footer(); ?>