homegrade_theme_production/single-conseils.php

62 lines
1.8 KiB
PHP

<?php
get_header();
function build_chapter_index($blocks)
{
$chapterIndex = [];
foreach ($blocks as $key => $block) {
if ($block['blockName'] == 'homegrade-content-blocks/questions-container') {
array_push($chapterIndex, $block['attrs']['relatedPostId']);
}
}
return $chapterIndex;
}
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$thematique = get_the_terms(get_the_ID(), 'thematiques')[0];
$thematiqueParent = getParentThematique($thematique);
$thematiqueColorSlug = getThematiqueFamilySlug($thematiqueParent->slug);
?>
<div class="post-conseil-page-container <?php echo $thematiqueColorSlug ? "post-conseil-page--" . $thematiqueColorSlug : "" ?>"">
<?php
$blocks = parse_blocks($post->post_content);
$chapterIndex = build_chapter_index($blocks);
?>
<?php get_template_part('template-components/post-conseils/chapter-header'); ?>
<div class=" conseils_wrapper">
<aside class="chapter_index">
<div class="chapter_index__titling">
<div class="icon"></div>
<h2 class="chapter_index__title">Dans ce conseil</h2>
</div>
<ul class="chapter_index__list">
<div class="chapter_index__position-indicator"></div>
<?php foreach ($chapterIndex as $chapterRelatedPostID) : ?>
<?php $chapterTitle = get_the_title($chapterRelatedPostID); ?>
<li class="chapter_index__link"><a href="#questions-container-<?php echo $chapterRelatedPostID ?>"><?php echo $chapterTitle ?></a></li>
<?php endforeach; ?>
</ul>
</aside>
<article class="container my-8 mx-auto entry-content single-editor-content <?php echo $thematiqueColorSlug ? "entry-content--" . $thematiqueColorSlug : "" ?>">
<?php the_content() ?>
</article>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php
get_footer();