taxonomy; $context['term'] = Timber::get_term($term); $context['taxonomy_slug'] = $taxonomy; $context['term_id'] = $term->term_id; $context['parent_slug'] = ''; $tax_object = get_taxonomy($taxonomy); $context['taxonomy_label'] = $tax_object ? $tax_object->labels->singular_name : $taxonomy; // Séance de séminaire, Non classé (+ Vie du labo pour les non-connectés) $excluded_ids = thalim_archive_excluded_cat_ids(); // Read filter query params $f = thalim_archive_read_filters(); $active_axe = $f['axe']; $active_date_from = $f['date_from']; $active_date_to = $f['date_to']; $active_cat_id = $f['cat_id']; $filter_autres = $f['filter_autres']; $context['active_axe'] = $active_axe; $context['active_date_from'] = $active_date_from; $context['active_date_to'] = $active_date_to; $context['active_category_id'] = $filter_autres ? 'autres' : $active_cat_id; $context['active_cat_id'] = $active_cat_id; $context['filter_autres'] = $filter_autres; // Determine active rubrique from active category (parent if subcategory, itself if top-level) $active_rubrique_id = thalim_archive_active_rubrique($active_cat_id); $context['active_rubrique'] = $active_rubrique_id; // Base params shared across all filter links (preserves active filters when navigating) $base_filter_params = array_filter([ 'axe' => $active_axe ?: null, 'date_from' => $active_date_from ?: null, 'date_to' => $active_date_to ?: null, ]); // Build tax_query — combine all clauses with AND $tax_query = [ 'relation' => 'AND', // Terme de la taxonomie courante [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => [$term->term_id], ], // Exclure les séances de séminaire [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => [ thalim_cat_id('seance') ], 'operator' => 'NOT IN', ], ]; if ($active_cat_id) { $tax_query[] = [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => [$active_cat_id], 'include_children' => !$filter_autres, ]; } // On axe_thematique pages, the current term IS the active axe (for display only — taxonomy query handles filtering) $axe_taxonomy_mode = ($taxonomy === 'axe_thematique'); if ($axe_taxonomy_mode) { $active_axe = $term->term_id; $context['active_axe'] = $active_axe; } // Build remaining query args (meta/date) $extra_query_args = []; if ($active_axe && !$axe_taxonomy_mode) { $extra_query_args['meta_query'] = [[ 'key' => 'axes_thematiques', 'value' => $active_axe, 'type' => 'NUMERIC', ]]; } if ($active_date_from || $active_date_to) { $extra_query_args['thalim_event_date_filter'] = ['from' => $active_date_from, 'to' => $active_date_to]; } // Axes thématiques filter $axes_groups = thalim_get_axes_filter_groups(); $current_axes = $axes_groups[0]['terms'] ?? []; $context['filter_axes'] = $current_axes; $context['axe_taxonomy_mode'] = $axe_taxonomy_mode; $context['axe_stay_on_page'] = !$axe_taxonomy_mode; // Build rubrique/catégorie filter links pointing back to the current taxonomy URL $current_term_url = get_term_link($term); $all_cats = get_categories(['taxonomy' => 'category', 'hide_empty' => false, 'exclude' => $excluded_ids]); // Liens de filtre : on reste sur l'URL du terme courant avec un paramètre filter_cat $make_filter_link = function ($cat) use ($base_filter_params, $current_term_url) { $params = array_filter(array_merge($base_filter_params, ['filter_cat' => $cat->term_id])); return add_query_arg($params, $current_term_url); }; $context['filter_parents'] = thalim_archive_filter_parents($all_cats, $make_filter_link); $filter_categories = thalim_archive_filter_children($all_cats, $active_rubrique_id, $make_filter_link); // Add "Autres" entry if active rubrique has posts directly assigned to it // (contraints au terme de taxonomie courant) if ($active_rubrique_id && !empty($filter_categories)) { $has_direct = thalim_rubrique_has_direct_posts($active_rubrique_id, [ [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => [$term->term_id], ], ]); if ($has_direct) { $params = array_filter(array_merge($base_filter_params, ['filter_cat' => $active_rubrique_id, 'filter_autres' => 1])); $filter_categories[] = thalim_archive_autres_entry(add_query_arg($params, $current_term_url)); } } $context['filter_categories'] = $filter_categories; $posts = Timber::get_posts(array_merge([ 'post_type' => 'post', 'tax_query' => $tax_query, 'posts_per_page' => 12, 'orderby' => 'date', 'order' => 'DESC', 'thalim_event_date_order' => true, ], $extra_query_args)); $context['cards'] = thalim_get_cards_data($posts); $context['posts'] = $posts; // Custom Pods presentation fields (not the WP built-in description) $tax_lang = thalim_current_language(); $pres_fr = get_term_meta($term->term_id, 'presentation', true) ?: ''; $pres_en = get_term_meta($term->term_id, 'presentation_en', true) ?: ''; $context['term_presentation'] = wpautop( wp_kses_post( ( $tax_lang === 'en' && $pres_en ) ? $pres_en : $pres_fr ) ); Timber::render('taxonomy.twig', $context);