119 lines
3.6 KiB
PHP
119 lines
3.6 KiB
PHP
<?php
|
|
get_header();
|
|
function build_chapter_index($blocks)
|
|
{
|
|
$chapterBlockIndex = [];
|
|
foreach ($blocks as $key => $block) {
|
|
if ($block['blockName'] == 'homegrade-content-blocks/questions-container') {
|
|
array_push($chapterBlockIndex, [
|
|
'block-type' => $block['blockName'],
|
|
'anchor' => '#questions-container-' . $block['attrs']['relatedPostId'],
|
|
'title' => get_the_title($block['attrs']['relatedPostId']),
|
|
]);
|
|
}
|
|
if ($block['blockName'] == 'homegrade-content-blocks/vocabulaire-summary') {
|
|
array_push($chapterBlockIndex, [
|
|
'block-type' => $block['blockName'],
|
|
'anchor' => "#vocabulaire-summary",
|
|
'title' => "Vocabulaire" . " " . get_the_terms(get_the_ID(), "thematiques")[0]->name,
|
|
]);
|
|
}
|
|
if ($block['blockName'] == 'homegrade-content-blocks/plus-loin') {
|
|
array_push($chapterBlockIndex, [
|
|
'block-type' => $block['blockName'],
|
|
'anchor' => "#aller-plus-loin",
|
|
'title' => __("Pour aller plus loin", "homegrade-blocks__texte-fonctionnel"),
|
|
]);
|
|
}
|
|
}
|
|
return $chapterBlockIndex;
|
|
}
|
|
?>
|
|
|
|
|
|
<?php if (have_posts()) : ?>
|
|
<?php while (have_posts()) : the_post(); ?>
|
|
<?php
|
|
$currentThematique = get_the_terms(get_the_ID(), 'thematiques')[0];
|
|
$mainThematique = getMainThematique($currentThematique);
|
|
$thematiqueColorSlug = $mainThematique->slug;
|
|
?>
|
|
|
|
<div class="post-conseil-page-container <?php echo $thematiqueColorSlug ? "post-conseil-page--" . $thematiqueColorSlug : "" ?>"">
|
|
<nav class=" breadcrumbs_navigation" aria-label="breadcrumbs">
|
|
<?php
|
|
$archiveConseils = get_page_by_template('template-archive-conseils.php')[0];
|
|
|
|
|
|
?>
|
|
<ol>
|
|
<li><a href="<?php echo home_url() ?>">Home</a></li>
|
|
<li><a href="<?php echo get_post_permalink($archiveConseils) ?>"><?php echo $archiveConseils->post_title ?></a></li>
|
|
<?php if ($mainThematique != $currentThematique) : ?>
|
|
<?php
|
|
$args = array(
|
|
'post_type' => 'conseils', // the post type
|
|
'tax_query' => array(
|
|
array(
|
|
'taxonomy' => 'thematiques', // the custom vocabulary
|
|
'field' => 'term_id', // term_id, slug or name
|
|
'terms' => array($mainThematique->term_id),
|
|
'include_children' => false,
|
|
),
|
|
),
|
|
);
|
|
$mainThematiqueRelatedConseil = get_posts($args)[0] ?? null;
|
|
?>
|
|
<li><a href="<?php echo get_post_permalink($mainThematiqueRelatedConseil) ?>"><?php echo $mainThematique->name ?></a></li>
|
|
|
|
<?php endif; ?>
|
|
<li><a href="<?php echo the_permalink() ?>" aria-current="location"><?php echo $currentThematique->name ?></a></li>
|
|
|
|
</ol>
|
|
</nav>
|
|
|
|
<?php
|
|
$blocks = parse_blocks($post->post_content);
|
|
$chapterBlockIndex = build_chapter_index($blocks);
|
|
?>
|
|
<?php get_template_part('template-components/post-conseils/chapter-header'); ?>
|
|
<div class=" conseils_wrapper">
|
|
<?php if ($chapterBlockIndex) : ?>
|
|
<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 ($chapterBlockIndex as $chapter) : ?>
|
|
<li class="chapter_index__link"><a href="<?php echo $chapter['anchor'] ?>"><?php echo $chapter['title'] ?></a></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</aside>
|
|
<?php endif; ?>
|
|
|
|
<!-- CHAPTER INDEX -->
|
|
|
|
|
|
|
|
|
|
|
|
<article class="entry-content single-editor-content <?php echo $thematiqueColorSlug ? "entry-content--" . $thematiqueColorSlug : "" ?>">
|
|
<?php the_content() ?>
|
|
</article>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<?php endwhile; ?>
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
get_footer();
|