<?php

/**
 * Cikkeket listázó sablont megvalósító fájl hagyományos megoldása
 */
get_header();
global $post;
$stickies = get_option('sticky_posts');

function getQuery($category, $sticky, $postsnum)
{
	$stickies = get_option('sticky_posts');
	if ($sticky == 'sticky') {
		$vals = [
			'post_type'           => ['post'],
			'post_status'         => 'publish',
			'post__in'       	  => $stickies,
			'posts_per_page'      => $postsnum,
			'order_by'            => 'date',
			'order'               => 'DESC',
			'category_name'	  	  => $category
		];
	}
	if ($sticky == 'not_sticky') {
		$vals = [
			'post_type'           => ['post'],
			'post_status'         => 'publish',
			'post__not_in'        => $stickies,
			'posts_per_page'      => $postsnum,
			'order_by'            => 'date',
			'order'               => 'DESC',
			'category_name'	 	  => $category
		];
	}
	if ($sticky == 'all') {
		$vals = [
			'post_type'           => ['post'],
			'post_status'         => 'publish',
			'posts_per_page'      => $postsnum,
			'order_by'            => 'date',
			'order'               => 'DESC',
			'category_name'	 	  => $category
		];
	}
	return $vals;
}



$sliderQuery = new WP_Query(getQuery('elhetovaros_fejlec', 'all', 1));
$sticky_elhetovaros = new WP_Query(getQuery('elhetovaros', 'sticky', 200));
$not_sticky_elhetovaros = new WP_Query(getQuery('elhetovaros', 'not_sticky', 200));
$all_elhetovaros = new WP_Query(getQuery('elhetovaros', 'all', 200));
$sticky_szakmai = new WP_Query(getQuery('szakmai-cikkek', 'sticky', 6));
// $not_sticky_szakmai = new WP_Query(getQuery('szakmai-cikkek', 'not_sticky', 200));
$all_szakmai = new WP_Query(getQuery('szakmai-cikkek', 'all', 6));
$sticky_monddel = new WP_Query(getQuery('mondd-el-a-velemenyed', 'sticky', 12));
// $not_sticky_monddel = new WP_Query(getQuery('mondd-el-a-velemenyed', 'not_sticky', 200));
$all_monddel = new WP_Query(getQuery('mondd-el-a-velemenyed', 'all', 12));

$counter1 = 0;
$counter2 = 0;
$counter3 = 0;
$counter4 = 0;

?>

<div id="content">
	<div id="inner-content" class="wrap cf">
		<main id="main" class="m-all cf" role="main">
			<?php if ($sliderQuery->have_posts()) : ?>
				<div class="row">

					<div class="col-md-12 col-sm-12 col-xs-12 item" style="padding-bottom: 20px;">

						<?php
						while ($sliderQuery->have_posts()) : $sliderQuery->the_post();

							if (has_post_thumbnail($post->ID)) :
								$do_not_duplicate = $post->ID;
								$category       = new stdClass();
								$categories     = wp_get_post_terms($post->ID, 'category');
								if (!is_wp_error($categories) && count($categories) > 0) {
									/* @var \WP_Term $category */
									$category = array_values($categories)[0];
								}

								$sliderImage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size = 'large', 'single-post-thumbnail');
						?>

								<div class="item <?php if ($post->post_type == 'post') {
														echo 'hl-news';
													} else {
														echo 'hl-projects';
													}  ?>">

									<article id="post-<?php the_ID(); ?>" role="article" class="articleThumb headArticle" style="background-image: url(<?php print $sliderImage[0]; ?>);">
										<div class="textOnLeft">
											<h1><?php the_title(); ?></h1>
											<p><?php the_content(); ?></p>
										</div>
										<div class="btnOnRight">
											<a href="https://enbudapestem.hu/mondd-el-a-velemenyed">
												Mondd el a véleményed! <span class="glyphicon glyphicon-hand-right" aria-hidden="true"></span>
											</a>
										</div>
									</article>
								</div>


						<?php
							endif;

						endwhile;
						wp_reset_query();
						?>

					</div>
				</div>
			<?php endif; ?>

			<div class="row">
				<div class="col-md-6">
					<?php
					if ($sticky_szakmai->have_posts()) :
						while ($sticky_szakmai->have_posts()) : $sticky_szakmai->the_post();
							if ($post->ID == $do_not_duplicate) continue;
							$articleImage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size = 'bones-thumb-800', 'single-post-thumbnail');
					?>

							<div class="item <?php if ($post->post_type == 'post') {
													echo 'hl-news';
												} else {
													echo 'hl-projects';
												}  ?>">

								<article id="post-<?php the_ID(); ?>" role="article" class="articleThumb leftColArticle" style="background-image: url(<?php print $articleImage[0]; ?>);">
									<h3 class="title">
										<a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" style="color:#fff;">
											<?php the_title(); ?>
										</a>
									</h3>
								</article>
							</div>
					<?php
							if (1 === $counter1) {
								break;
							}
							$counter1++;

						endwhile;
					endif;
					wp_reset_query(); ?>
				</div> <!-- col-md-6 -->
				<div class="col-md-6">
					<?php
					if ($sticky_szakmai->have_posts()) :
						while ($sticky_szakmai->have_posts()) : $sticky_szakmai->the_post();
							if ($post->ID == $do_not_duplicate) continue;
							$articleImage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size = 'bones-thumb-800', 'single-post-thumbnail');
					?>

							<div class="item <?php if ($post->post_type == 'post') {
													echo 'hl-news';
												} else {
													echo 'hl-projects';
												}  ?>">

								<article id="post-<?php the_ID(); ?>" role="article" class="articleThumb rightColArticle">

									<div class="col-md-8 textblock">
										<h4 class="title"><a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
										<div class="contentText"><?php echo the_excerpt(); ?></div>
									</div>
									<a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
										<div class="col-md-4 imgblock" style="background-image: url(<?php print $articleImage[0]; ?>);">
										</div>
									</a>
								</article>
							</div>
					<?php
							if (4 === $counter1) {
								break;
							}
							$counter1++;
						endwhile;
					endif;
					wp_reset_query(); ?>
				</div> <!-- col-md-6 -->
				<div class="col-md-12 col-xs-12">
					<div class="text-center" style="margin: 45px 0 15px 0">
						<a href="https://enbudapestem.hu/szakmai-cikkek" class="btn btn-lg btn-default text-center">További szakmai cikkek</a>
					</div>
				</div>
			</div> <!-- row -->


			<div class="row">
				<div class="col-md-12" id="mondd-el-a-velemenyed">
					<div class="row sectionVelemeny" style="background: url(https://enbudapestem.hu/wp-content/uploads/2020/08/SBT_8415s.jpg);">
						<a href="https://enbudapestem.hu/mondd-el-a-velemenyed" class="btn btn-lg btn-default sectioncenter">Mondd el a véleményed! <span class="glyphicon glyphicon-hand-right" aria-hidden="true"></span></a>
					</div>
				</div>


				<?php
				if ($all_monddel->have_posts()) :
					while ($all_monddel->have_posts()) : $all_monddel->the_post();
						if ($post->ID == $do_not_duplicate) continue;
						$category       = new stdClass();
						$categories     = wp_get_post_terms($post->ID, 'category');
						if (!is_wp_error($categories) && count($categories) > 0) {
							/* @var \WP_Term $category */
							$category = array_values($categories)[0];
						}
						$articleImage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size = 'bones-thumb-800', 'single-post-thumbnail');
				?>
						<div class="col-md-6 noLeftPaddingDesktop">
							<div class="item <?php if ($post->post_type == 'post') {
													echo 'hl-news';
												} else {
													echo 'hl-projects';
												}  ?>">

								
							<a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
								<article id="post-<?php the_ID(); ?>" class="articleThumb rightColArticle">

									<div class="col-md-8 textblock">
										<h4 class="title"><a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
										<div class="contentText"><?php echo the_excerpt(); ?></div>
									</div>
									<a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
										<div class="col-md-4 imgblock" style="background-image: url(<?php print $articleImage[0]; ?>);">
										</div>
									</a>
								</article>
							</a>
							</div>

						</div>
				<?php
						$counter2++;
					endwhile;
				endif;
				wp_reset_query(); ?>
			</div>
			<div class="row">
				<div class="col-md-12">
					<div class="row sectionHirek" style="background: url(https://enbudapestem.hu/wp-content/uploads/2020/08/SBT_4301.jpg);">
						<h2 class="sectionbottom">Hírek</h2>
					</div>
				</div>
			</div>

			<div class="row">
				<?php
				if ($all_elhetovaros->have_posts()) :
					while ($all_elhetovaros->have_posts()) : $all_elhetovaros->the_post();
						if ($post->ID == $do_not_duplicate) continue;
						$category       = new stdClass();
						$categories     = wp_get_post_terms($post->ID, 'category');
						if (!is_wp_error($categories) && count($categories) > 0) {
							/* @var \WP_Term $category */
							$category = array_values($categories)[0];
						}
						$articleImage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size = 'bones-thumb-800', 'single-post-thumbnail');
				?>
						<div class="col-md-6 newsblock" style="margin-bottom: 30px;">

							<div class="item <?php if ($post->post_type == 'post') {
													echo 'hl-news';
												} else {
													echo 'hl-projects';
												}  ?>">

								<a onclick="return gtag_report_conversion('<?php the_permalink(); ?>');" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" style="color:#fff;">
									<article id="post-<?php the_ID(); ?>" role="article" class="articleThumb leftColArticle" style="background-image: url(<?php print $articleImage[0]; ?>);">
										<h3 class="title">
											<?php the_title(); ?>
										</h3>
									</article>
								</a>
							</div>

						</div>
				<?php
						$counter3++;
					endwhile;
				endif;
				wp_reset_query(); ?>
			</div>
		</main>
	</div>
</div>

<?php get_footer(); ?>