<?php
/**
 * Glówny plik motywu
 *
 * @link https://krzysztof-turek.com
 *
 * @package tylkofotografia.pl
 * @version 0.2
 */
$postcount = 0;

$paged = get_query_var("paged") ? get_query_var("paged") : 1;
$tag = get_query_var("tag_id") ? get_query_var("tag_id") : "";
$category = get_query_var("cat");
$args = [
    "post_type" => ["post", "page"],
    "posts_per_page" => 10, // Set the number of posts per page
    "paged" => $paged, // Set the page number
    "tag_id" => $tag,
    "cat" => $category, // Filter by category ID
    //'tag__not_in' => array(120),  Filter by excluding a specific tag ID
    "post_status" => "publish",
    "post__not_in" => [
        2421,
        796,
        324,
        1338,
        1743,
        263,
        260,
        3,
        1615,
        1713,
        360,
        906,
        1071,
        339,
        336,
    ],
];

$the_query = new WP_Query($args);

Excerpt::getInstance();
get_header();
?>
	<main>
 <div class="content" id="main">
	<div class="container">
		<div id="primary" class="row content">
		<?php if ($the_query->have_posts()) {
      while ($the_query->have_posts()):

          $the_query->the_post();
          $postcount++;
          ?>
			<article id="post-<?php the_ID(); ?>" class="col-lg-6 col-xs-12 front-page mb-5">
			<?php if (has_post_thumbnail()) { ?>


				<a href="<?php the_permalink($post->ID); ?>">
					<figure class="text-center">
						<?php if ($postcount < 5) {
          the_post_thumbnail("large", ["loading" => ""]);
      } else {
          the_post_thumbnail("large", ["loading" => "lazy"]);
      } ?>
					</figure>
					</a>
					<div class="d-flex justify-content-between bd-highlight mb-2">
						<div class="p-2 bd-highlight">
								<small><i class="fas fa-user"></i> <?php the_author(); ?></small>
						</div>
						<div class="p-2 text-center">
							<i class="fab fa-youtube"></i> <?php
       $categories = get_the_category();
       echo $categories[0]->name;
       ?>
						</div>
						<div class="p-2 bd-highlight">
							<small ><i class="far fa-clock"></i><time> <?php echo get_the_date(); ?><time></small>

						</div>
					</div>
					<div style="margin:auto">
                        <div class="col-12 h-100">
							<p style="min-height: 100px;">
									<?php echo get_the_excerpt(); ?>
							</p>
							<p class="text-right"><a href="<?php echo get_the_permalink(
           $postId,
       ); ?>">Więcej...</a></p>
						</div>
					</div>

				<hr />
			<?php } ?>
			</article>
			<?php if ($postcount % 2 == 0) { ?>
			</div><div class="row content">
			<?php } ?>

		<?php
      endwhile;
  } else {
      get_template_part("template-parts/content/nocontent");
  } ?>
		</div>
		<nav class="d-flex justify-content-between bd-highlight mb-2" role="navigation">

            <div class="p-2 bd-highlight"><?php next_posts_link(
                '<i class="fas fa-arrow-left"></i> Starsze posty',
            ); ?></div>
            <div class="p-2 bd-highlight"><?php previous_posts_link(
                'Nowsze posty <i class="fas fa-arrow-right"></i>',
            ); ?></div>
        </nav>
	</div>
</div>
</main>
<?php get_footer();
