<?php /* Template Name: Conseils | Archive */
get_header();
$thematiquesTerms = get_terms(array(
	'taxonomy'   => 'thematiques',
	'hide_empty' => false,
	'parent' => 0
));
$page_icon = get_field('page_icon', get_queried_object());
?>

<div class="homegrade-page-container  homegrade-page-container--archive-conseils">
	<nav class="breadcrumbs_navigation" aria-label="<?php echo __("Vous êtes ici", "homegrade-theme__texte-fonctionnel") ?>">
		<ol>
			<li>
				<a href="<?php echo home_url() ?>" title="<?php echo __("Accueil", "homegrade-theme__texte-fonctionnel") ?>">
					<img src="<?php echo get_template_directory_uri() . "/resources/img/pictogrammes/icon_house_dark.svg" ?>" alt="">
				</a>
			</li>
			<li><a href="<?php echo get_post_type_archive_link('conseils') ?>" aria-current='location'>Nos conseils</a></li>
		</ol>
	</nav>

	<section class="archive-page-header">

		<?php if ($page_icon) : ?>
			<img class="archive-page-header__icon" src="<?php echo $page_icon['url'] ?>" alt="" />
		<?php endif; ?>

		<h1 class="archive-page-header__title"><?php echo __("Nos conseils par thématique", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></h1>
		<p class="archive-page-header__description"><?php echo __("Simplifions votre recherche par thématiques !", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></p>
		<ul class="archive-page-header__terms-grid">
			<?php foreach ($thematiquesTerms as $thematique) : ?>
				<?php
				if ($term->slug === "aides-financieres" || $term->slug === "financiele-steun") continue;

				$original_term_ID = apply_filters('wpml_object_id', $thematique->term_id, 'thematiques', FALSE, 'fr');
				$thematique_icon = get_field('taxonomy_pictures', $thematique->taxonomy . '_' . $original_term_ID)['icon'];
				$termSlug = getThematiqueFamilySlug($thematique->slug);

				$args = array(
					'posts_per_page' => 1,
					'post_type'   => 'conseils',
					'tax_query' => array(
						array(
							'taxonomy' => 'thematiques',
							'field' => 'term_id',
							'terms' => $thematique->term_id,
							'include_children' => false
						)
					)
				);

				$relatedThematiqueConseilsQuery = new WP_Query($args);
				$relatedPostConseil = $relatedThematiqueConseilsQuery->posts[0] ?? null;
				?>
				<?php if ($relatedPostConseil) : ?>
					<li class="term">
						<a href="<?php echo get_permalink($relatedPostConseil->ID) ?>">
							<img src="<?php echo $thematique_icon['url'] ?>" alt="">
							<p class="text-<?php echo $termSlug ?>"><span class="sr-only">Question </span><?php echo $thematique->name ?></p>
						</a>
					</li>

				<?php endif; ?>
			<?php endforeach; ?>
		</ul>

	</section>

	<section class="homegrade-help card-large-content-container">

		<div class="card-large-content card-large-content--has-illustration">
			<img class="card-large-content__top-illustration" src='<?php echo get_template_directory_uri() ?>/resources/img/illustrations/illustration-homegrade-help.svg' alt=''>

			<div class="section_titling">
				<h2 class="section_titling__title"><?php echo __("Comment Homegrade peut vous aider ?", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></h2>
				<p class="section_titling__subtitle"><?php echo __("Homegrade met à disposition des outils en ligne pour vous aider dans votre recherche", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></p>
			</div>
			<div class="card-large-content__links-container">
				<!-- PUBLICATIONS -->
				<div class="card-large-content__link">
					<?php $publication_page_ID = apply_filters('wpml_object_id', 106, 'page', TRUE); ?>
					<img class="card-large-content__link__page_icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-outils.svg' ?>" alt="">
					<h3 class="card-large-content__link__title"><?php echo get_the_title($publication_page_ID) ?></h3>
					<p class="card-large-content__link__excerpt"><?php echo get_the_excerpt($publication_page_ID) ?></p>
					<a class="cta cta--button cta--shadowed" href="<?php echo get_permalink($publication_page_ID) ?>"><?php echo __("Accédez aux publications", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></a>
				</div>
				<!-- FAQ -->
				<div class="card-large-content__link">
					<?php $faq_page_ID = apply_filters('wpml_object_id', 60, 'page', TRUE); ?>
					<img class="card-large-content__link__page_icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-faq.svg' ?>" alt="">
					<h3 class="card-large-content__link__title"><?php echo get_the_title($faq_page_ID)  ?></h3>
					<p class="card-large-content__link__excerpt"><?php echo  get_the_excerpt($faq_page_ID) ?></p>
					<a class="cta cta--button cta--shadowed" href="<?php echo get_permalink($faq_page_ID) ?>"><?php echo __("Accédez aux questions", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></a>
				</div>
				<!-- SERVICE -->
				<div class="card-large-content__link">
					<?php
					$services_page_ID = apply_filters('wpml_object_id', 52, 'page', false);

					?>
					<img class="card-large-content__link__page_icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-services.svg' ?>" alt="">
					<h3 class="card-large-content__link__title"><?php echo get_the_title($services_page_ID)  ?></h3>
					<p class="card-large-content__link__excerpt"><?php echo  get_the_excerpt($services_page_ID) ?></p>
					<a class="cta cta--button cta--shadowed" href="<?php echo get_permalink($services_page_ID) ?>"><?php echo __("Voir les services", "homegrade-theme__texte-fonctionnel__faq-archive-questions") ?></a>
				</div>


			</div>



		</div>



	</section>
</div>



<?php
get_footer();
