diff --git a/includes/utilities.php b/includes/utilities.php index c8690a4..b1a96a4 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -271,7 +271,47 @@ function build_page_chapter_index($blocks) } /* ------------------------------------------- - GET PARCOURS PREVIOUS/NEXT POSTS + GET ALL THEMATIQUES ORGANIZED BY PARENTS + ---------------------------------------------*/ +function getAllThematiquesTermsByParents() +{ + // Récupérer tous les termes de la taxonomie 'thematiques' avec une hiérarchie + $ThematiquesTerms = get_terms([ + 'taxonomy' => 'thematiques', + 'orderby' => 'name', + 'order' => 'ASC', + 'hide_empty' => true, + ]); + + $terms_by_parent = []; + $child_terms = []; + + if ($ThematiquesTerms) { + + // Boucle pour organiser les termes en fonction de leurs parents + foreach ($ThematiquesTerms as $term) { + if ($term->parent == 0) { + // Si c'est un parent, on le place dans le tableau des parents + $terms_by_parent[$term->term_id] = ['term' => $term, 'children' => []]; + } else { + $child_terms[$term->parent][] = $term; + } + } + + + // Réunir les termes parents et leurs enfants + foreach ($terms_by_parent as $parent_id => &$parent_data) { + // Ajouter les enfants au parent + if (isset($child_terms[$parent_id])) { + $parent_data['children'] = $child_terms[$parent_id]; + } + } + } + return $terms_by_parent; +} + +/* ------------------------------------------- + GET PARCOURS PREVIOUS/NEXT POSTS ---------------------------------------------*/ function get_parcours_previous_next_posts($post)