moving build_chapter_index into utilities function
This commit is contained in:
parent
d1c3b69bc0
commit
db01517f67
|
|
@ -1,48 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
get_header();
|
get_header();
|
||||||
if (!function_exists('build_share_urls')) {
|
|
||||||
function build_chapter_index($blocks)
|
|
||||||
{
|
|
||||||
$chapterBlockIndex = [];
|
|
||||||
foreach ($blocks as $key => $block) {
|
|
||||||
if ($block['blockName'] == 'homegrade-content-blocks/chapitrage-thematique') {
|
|
||||||
foreach ($block['innerBlocks'] as $key => $innerBlock) {
|
|
||||||
if (!$innerBlock['attrs']['chapterTitle']) continue;
|
|
||||||
|
|
||||||
$cleanedTitle = strtolower(preg_replace("/[^a-zA-Z]/", "", $innerBlock['attrs']['chapterTitle']));
|
|
||||||
|
|
||||||
array_push($chapterBlockIndex, [
|
|
||||||
'block-type' => $block['blockName'],
|
|
||||||
'anchor' => '#' . $cleanedTitle,
|
|
||||||
'title' => $innerBlock['attrs']['chapterTitle'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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", "homegrade-theme__texte-fonctionnel") . " " . 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 if (have_posts()) : ?>
|
||||||
<?php while (have_posts()) : the_post(); ?>
|
<?php while (have_posts()) : the_post(); ?>
|
||||||
|
|
@ -93,7 +51,7 @@ if (!function_exists('build_share_urls')) {
|
||||||
---------------*/ ?>
|
---------------*/ ?>
|
||||||
<?php
|
<?php
|
||||||
$blocks = parse_blocks($post->post_content);
|
$blocks = parse_blocks($post->post_content);
|
||||||
$chapterBlockIndex = build_chapter_index($blocks);
|
$chapterBlockIndex = build_page_chapter_index($blocks); // see utilities.php
|
||||||
$queryArgs = array(
|
$queryArgs = array(
|
||||||
'post_type' => 'brochures',
|
'post_type' => 'brochures',
|
||||||
'posts_per_page' => 1,
|
'posts_per_page' => 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user