<?php
// NEEDS TO BE A QUERY POST OBJECT
$brochuresPosts = $args['brochuresPosts'];
?>

<?php if ($brochuresPosts->have_posts()) : while ($brochuresPosts->have_posts()) : $brochuresPosts->the_post(); ?>
		<?php
		$brochurePdf = get_field('brochure_pdf', $args['ID']);
		$brochureCover = get_field('brochure_cover_image', $brochurePdf['ID']);
		$brochureEdition = get_field('brochure_edition', $args['ID']);
		$thematique = get_the_terms($args['ID'], 'thematiques')[0];
		$rootThematic = getParentThematique($thematique);
		?>

		<li class="publications-grid__row">
			<?php if ($brochureCover) : ?>
				<img class="publications-grid__cover" src="<?php echo $brochureCover['sizes']['medium'] ?>" />
			<?php endif; ?>
			<h2 class="publications-grid__title"><?php echo $brochurePdf['title'] ?></h2>
			<p class="publications-grid__thematique thematique-tag thematique-tag--<?php echo $rootThematic->slug ?>"><?php echo $rootThematic->name ?></p>

			<?php if ($brochureEdition) : ?>
				<p class="publications-grid__edition"><?php echo $brochureEdition ?></p>
			<?php endif; ?>
			<div class="publications-grid__button">
				<a href="<?php echo $brochurePdf['url'] ?>" class=" cta cta--secondary cta--button" href="#" target="_blank"><?php echo __("Consulter le pdf", "homegrade-theme__texte-fonctionnel__publications-archive") ?></a>
			</div>
		</li>

	<?php endwhile ?>
<?php endif; ?>