homegrade_blocks_production/blocks/post-card/build/render.php

34 lines
1.4 KiB
PHP

<?php
$relatedPostId = $attributes['relatedPostId'] ?? null;
$postType = get_post_type_object(get_post_type($relatedPostId));
$relatedPost = get_post($relatedPostId) ?? null;
$relatedPostUrl = get_permalink($relatedPostId) ?? null;
$postThumbnail = get_the_post_thumbnail_url($relatedPostId) ?? null;
$target = $postType->name === 'fiches-infos' ? "_blank" : "_self";
$thematique = get_the_terms($relatedPostId, 'thematiques')[0];
$mainThematique = getMainThematique($thematique);
$thematiqueColorSlug = $mainThematique->slug;
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];
$coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail ? $postThumbnail : ($thematique_icon ? $thematique_icon['url'] : null);
?>
<a class="post-card" href="<?php echo $relatedPostUrl ?>" target="<?php echo $target ?>">
<img class="post-card__cover post-card__cover--<?php echo $postType->name ?>" src="<?php echo $coverUrl ?>" alt="">
<div class="post-card__details">
<div class="post-card__tags">
<?php if ($mainThematique) : ?>
<div class="tag thematique-tag thematique-tag--<?php echo $mainThematique->slug ?>"><?php echo $mainThematique->name ?></div>
<?php endif; ?>
<div class="tag post-type-tag"><?php echo $postType->label ?></div>
</div>
<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
</div>
</a>