correction doublons index Ajax + découplage slug categories couleurs

This commit is contained in:
2026-06-04 17:41:11 +02:00
parent d900e7aa65
commit bea33f9fd3
5 changed files with 92 additions and 36 deletions

View File

@@ -10,10 +10,10 @@ if ( ! is_user_logged_in() ) $excluded_ids[] = 9; // Vie du labo
// Parent category slug for color theming
if ($category->parent) {
$parent_cat = get_category($category->parent);
$context['parent_slug'] = $parent_cat->slug;
$context['parent_slug'] = thalim_category_color_slug($parent_cat->term_id, $parent_cat->slug);
$context['active_rubrique'] = $parent_cat->term_id;
} else {
$context['parent_slug'] = $category->slug;
$context['parent_slug'] = thalim_category_color_slug($category->term_id, $category->slug);
$context['active_rubrique'] = $category->term_id;
}
@@ -227,6 +227,12 @@ if (!$is_direct && !empty($children)) {
} else {
$context['is_parent'] = false;
$context['is_direct'] = $is_direct;
// Épinglés sortis du flux principal (et exclus de la pagination AJAX par thalim_load_more_posts),
// affichés dans un bloc dédié en tête. Garde l'initial et l'AJAX sur le même univers : sinon la
// fenêtre de pagination se décale et le post de la couture est dupliqué.
$pinned_ids = thalim_get_active_pinned_ids( $category->term_id );
$query_args = array_merge([
'post_type' => 'post',
'tax_query' => [[
@@ -241,9 +247,24 @@ if (!$is_direct && !empty($children)) {
'lang' => '',
'thalim_event_date_order' => true,
], $extra_query_args);
$posts = $sort_with_pinned( Timber::get_posts($query_args) );
$context['cards'] = thalim_get_cards_data($posts);
$context['posts'] = $posts;
if ( $pinned_ids ) {
$query_args['post__not_in'] = $pinned_ids;
}
$posts = Timber::get_posts($query_args);
// Pinned posts, respecting the active axe/date filters (so a pin outside the filter doesn't show).
$pinned_posts = $pinned_ids ? Timber::get_posts( array_merge([
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $pinned_ids,
'orderby' => 'post__in',
'posts_per_page' => -1,
'lang' => '',
], $extra_query_args ) ) : [];
$context['cards'] = thalim_get_cards_data($pinned_posts) + thalim_get_cards_data($posts);
$context['pinned_posts'] = $pinned_posts;
$context['posts'] = $posts;
}
// View mode toggle (?view=agenda)