<?php
/**
 * The template for displaying all categories for Posts
 *
 * 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 WordPress
 * @subpackage IZI_THEME
 * @since 1.0.0
 */

get_header();
?>
	<!-- /* INTERNAL PAGE HEADER IMG -->
	<div class="container-fluid p-0 position-relative pagehead">
		<div class="filterdiv internalpage position-absolute top-0 start-0"></div>
		<?php
		if (has_post_thumbnail()) {
			the_post_thumbnail('full', ['class' => 'img-fluid w-100']); 
		} else {
			echo '<img src="' . get_template_directory_uri() . '/assets/img/actu/fallout-serie-tv.jpg" class="img-fluid w-100" alt="Actu Séries" loading="lazy">';
		}
		?>
	<!-- <img class="img-fluid w-100" src="assets/img/series/the-boys.jpg" alt="Stranger Things"> -->
	</div>
	<!-- IMG END -->

	<!-- PAGE CONTENT -->
	<section class="container mt-5">
		<h1 class="htitles text-center my-5"><?php single_cat_title(); ?></h1>
		<?php echo category_description(); ?>
		
		<?php
		$cpt = 0;
			if ( have_posts() ) : while ( have_posts() ) : the_post();
				if ($cpt%2 !== 1) {  ?>
				<div class="row justify-content-md-center g-0">
					<div class="col-lg-4 col-xl-3 my-4 catimg">
					<?php 
						if ( has_post_thumbnail() ) {
							the_post_thumbnail('cat-thumb', array('class' => 'card-img'));
						} else {
							echo '<img src="'.get_template_directory_uri() . '/assets/img/actu/fallout-serie-tv.jpg" class="card-img" alt="Actu séries" loading="lazy" >';
						}
					?>
					</div>
					<div class="col-lg-8 col-xl-9 mb-4">
						<div class="card-body">
							<h2 class="card-title mb-3"><?php the_title(); ?></h2>
							<?php echo get_the_excerpt(); ?>
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-dark mt-3 float-end">en savoir +</a>
						</div>
					</div>
				</div>

			<?php 
				$cpt++;
			} else { ?>
				<div class="row justify-content-md-center g-0">
					<div class="col-12 order-first order-lg-last col-lg-4 col-xl-3 my-4 catimg">
					<?php 
						if ( has_post_thumbnail() ) {
							the_post_thumbnail('cat-thumb', array('class' => 'card-img'));
						} else {
							echo '<img src="'.get_template_directory_uri() . '/assets/img/actu/fallout-serie-tv.jpg" class="card-img" alt="Actu séries" loading="lazy" >';
						}
					?>
					</div>
					<div class="col-12 order-last order-lg-first col-lg-8 col-xl-9 mb-4">
						<div class="card-body">
							<h2 class="card-title mb-3"><?php the_title(); ?></h2>
							<?php echo get_the_excerpt(); ?>
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="btn btn-dark mt-3 float-end">en savoir -</a>
						</div>
					</div>
				</div>
			<?php
				$cpt++;
			}
			endwhile; else: ?>
			<div class="article-content">
				<p>Aucun contenu à afficher</p>
			</div>
		<?php endif; ?>

		<div class="row justify-content-center my-4">
			<nav aria-label="Page navigation">
				<ul class="pagination">
					<li class="page-item">
						<a class="page-link" href="#" aria-label="Previous">
							<span aria-hidden="true">&laquo;</span>
						</a>
					</li>
					<li class="page-item"><a class="page-link" href="#">1</a></li>
					<li class="page-item"><a class="page-link" href="#">2</a></li>
					<li class="page-item"><a class="page-link" href="#">3</a></li>
					<li class="page-item">
						<a class="page-link" href="#" aria-label="Next">
							<span aria-hidden="true">&raquo;</span>
						</a>
					</li>
				</ul>
			</nav>
		</div>
		<div class="row my-4">
			<nav class="paginate d-flex justify-content-center">
				<?php
				echo paginate_links( array(
					'show_all'			=> true,
					'prev_text'			=> '&laquo;',
					'next_text'			=> '&raquo;',
				) );
				?>
			</nav>
		</div>
	</section>
	<!-- PAGE CONTENT END -->
		
	<?php
	// Restore original post data.
	wp_reset_postdata();
	?>

	<?php
get_template_part('template-parts/content-videobg');
get_template_part('template-parts/content-prefooter');
get_footer();