parent == 0) { return $thematique; } else { return get_term($thematique->parent, 'thematiques'); } } // DOES THE SAME THING AS ABOVE BUT RENAMED function getMainThematique($thematique) { if (!$thematique) { return null; } if ($thematique->parent == 0) { return $thematique; } else { return get_term($thematique->parent, 'thematiques'); } } // DOES THE SAME THING AS ABOVE BUT RENAMED function getPostMainThematique($post) { return getMainThematique(get_the_terms($post, "thematiques")[0]); } // TO GET ARCHIVE RELATED PAGES BY TEMPLATE function get_page_by_template($template = '') { $args = array( 'meta_key' => '_wp_page_template', 'meta_value' => $template ); return get_pages($args); } function show_post_type_label_name($post_type) { switch ($post_type) { case 'questions': return __("Question", "homegrade-theme__texte-backoffice"); case 'conseils': return __("Conseil", "homegrade-theme__texte-backoffice"); case 'page': return __("Page", "homegrade-theme__texte-backoffice"); case 'post': return __("News", "homegrade-theme__texte-backoffice"); case 'jobs': return __("Offre d'emploi", "homegrade-theme__texte-backoffice"); default: return null; } } /* --------- SORT BY THEMATIQUE PRIORITY -----------------*/ // Fonction de comparaison pour trier par 'thematique_priority' utilisé par la fonction supérieur function compareThematiquePriority($postA, $postB) { $priorityA = $postA->thematique_priority ?? 0; $priorityB = $postB->thematique_priority ?? 0; if ($priorityA == $priorityB) { if ($postA->post_date > $postB->post_date) { return -1; } else { return 1; } } if ($priorityA < $priorityB) { return 1; } if ($priorityA > $priorityB) { return -1; } } function sort_posts_per_thematiques_priority($postsQuery) { foreach ($postsQuery->posts as $key => $post) { $thematique = getPostMainThematique($post); $post->thematique_priority = get_field('thematique_order', $thematique) ?? 0; } // 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; }