<?php

/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Sika
 */

get_header();
?>

<section class="feat-post-section">
	<div class="container">
		<div class="feat-post-wrap">
			<?php
			$sika_feat_post_slider = absint(get_theme_mod('sika_feat_slider_setting'));
			$query_args = array(
				'post_type' => 'post',
				'ignore_sticky_posts' => true,
				'posts_per_page' => 2,
				'cat' => $sika_feat_post_slider
			);

			$query = new WP_Query($query_args);
			if ($query->have_posts()) :
			?>

				<?php
				$i = 1;
				while ($query->have_posts()) :
					$query->the_post();
				?>

					<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
						<div class="card-item card-blog-post">
							<?php
							if (has_post_thumbnail()) {
							?>
								<div class="card-media">
									<?php sika_post_thumbnail(); ?>
								</div>
								<!-- .card-media -->
							<?php
							}
							?>

							<div class="card-body">
								<header class="entry-header">
									<?php
									if ('post' === get_post_type()) :
									?>
										<div class="entry-meta">
											<?php
											sika_posted_on();
											sika_posted_by();
											?>
										</div><!-- .entry-meta -->
										<?php

										the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');

										$categories_list = get_the_category_list(esc_html(' ', 'sika'));
										if ($categories_list) {
											/* translators: 1: list of categories. */
											printf('<span class="cat-links">' . esc_html('%1$s', 'sika') .  '</span>', $categories_list); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
										}
										endif;
										?>
								</header><!-- .entry-header -->

								<div class="entry-content">
									<?php
									if (is_singular()) :
										the_content();
									else :
										echo "<p>" . wp_trim_words(get_the_excerpt(), 30) . "</p>";
									?>
										<a href="<?php the_permalink(); ?>" class="btn read-btn text-uppercase"> <?php echo esc_html(get_theme_mod('sika_read_more_text', __('Read More', 'sika'))); ?> </a>
									<?php
									endif;
									?>


									<?php
									wp_link_pages(
										array(
											'before' => '<div class="page-links">' . esc_html__('Pages:', 'sika'),
											'after'  => '</div>',
										)
									);
									?>
								</div><!-- .entry-content -->
							</div>
							<!-- .card-body -->
						</div>
						<!-- .card-item -->
					</article>
					<!-- #post-<?php the_ID(); ?> -->
			<?php

				endwhile;
				wp_reset_postdata();
			endif;
			?>
		</div>
	</div>
</section>
<!-- .feat-post-section -->

<section class="feat-grid-section">
	<div class="container">
		<div class="feat-grid-wrap">
			<?php 
			$sika_feat_post_grid = absint(get_theme_mod('sika_feat_post_grid_setting'));
			$query_args = array(
				'post_type' => 'post',
				'ignore_sticky_posts' => true,
				'posts_per_page' => 6,
				'cat' => $sika_feat_post_grid
			);

			$query = new WP_Query($query_args);
			if ($query->have_posts()) :
			?>

				<?php
				$i = 1;
				while ($query->have_posts()) :
					$query->the_post();
				?>

					<article id="post-<?php the_ID(); ?>">
						<div class="card-item card-blog-post">
							<?php
							if (has_post_thumbnail()) {
							?>
								<div class="card-media">
									<?php sika_post_thumbnail(); ?>
								</div>
								<!-- .card-media -->
							<?php
							}
							?>

							<div class="card-body">
								<header class="entry-header">
									<?php
									if ('post' === get_post_type()) :
									?>
										<div class="entry-meta">
											<?php
											sika_posted_on();
											//sika_posted_by();
											?>
										</div><!-- .entry-meta -->
										<?php

										the_title('<h3 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h3>');

										$categories_list = get_the_category_list(esc_html(' ', 'sika'));
											if ($categories_list) {
												/* translators: 1: list of categories. */
												printf('<span class="cat-links">' . esc_html('%1$s', 'sika') .  '</span>', $categories_list); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
											}
										endif;
										?>
								</header><!-- .entry-header -->
							</div>
							<!-- .card-body -->
						</div>
						<!-- .card-item -->
					</article>
					<!-- #post-<?php the_ID(); ?> -->
			<?php

				endwhile;
				wp_reset_postdata();
			endif;
			?>
		</div>
	</div>
</section>
<!-- .feat-grid-section -->

<div class="container">
	<div class="main-wrapper ">
		<main id="primary" class="site-main ct-post-wrapper">
			<?php
			if (have_posts()) :

				if (is_home() && !is_front_page()) :
				?>
					<header>
						<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
					</header>
				<?php endif; ?>

				<!-- /* Start the Loop */ -->
				<div class="sika-content-area sika-masonry">
					<?php while (have_posts()) :
						the_post();

						/*
						* Include the Post-Type-specific template for the content.
						* If you want to override this in a child theme, then include a file
						* called content-___.php (where ___ is the Post Type name) and that will be used instead.
						*/
						get_template_part("template-parts/content", get_post_type());
					endwhile; ?>
				</div>
			<?php 
				the_posts_navigation();

			else :
				get_template_part("template-parts/content", "none");
			endif; ?>
		</main>
		<!-- #main -->

		<?php
		get_sidebar();	?>

	</div>

</div>
<!-- .main-wrapper -->

<?php
get_footer();