refactoring utilities and including build_page_chapter_index function
This commit is contained in:
parent
bc13d51900
commit
7fad8c9af4
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
$theme_namespace = 'homegrade-theme__texte-fonctionnel';
|
||||
|
||||
/* -------------------------------------------
|
||||
GET THEMATIQUE FAMILY (FOR COLOR SCHEME)
|
||||
---------------------------------------------*/
|
||||
function getThematiqueFamilySlug($thematique_slug)
|
||||
{
|
||||
if (!$thematique_slug) {
|
||||
|
|
@ -41,6 +45,9 @@ function getThematiqueFamilySlug($thematique_slug)
|
|||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------
|
||||
GETTING MAIN ROOT THEMATIQUE
|
||||
---------------------------------------------*/
|
||||
function getParentThematique($thematique)
|
||||
{
|
||||
if (!$thematique) {
|
||||
|
|
@ -146,8 +153,54 @@ function sort_posts_per_thematiques_priority($postsQuery)
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Tri du tableau en utilisant la fonction de comparaison
|
||||
usort($postsQuery->posts, 'compareThematiquePriority');
|
||||
return $postsQuery;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------
|
||||
Build The page chaptering index
|
||||
---------------------------------------------*/
|
||||
|
||||
function build_page_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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user