// Fonction pour formater l'heure function gram_event_format_time($time) { if (empty($time)) return ''; if (preg_match('/^\d{2}:\d{2}$/', $time)) { return $time; } $timestamp = strtotime($time); return $timestamp ? date_i18n('H:i', $timestamp) : $time; } // Fonction pour obtenir les détails de dates avec précision function gram_event_get_date_details($start_date, $end_date) { if (!$start_date) return ''; $start_formatted = gram_event_format_date($start_date); if (!$end_date || $end_date === $start_date) { return "Le " . $start_formatted; } $end_formatted = gram_event_format_date($end_date); $start_timestamp = strtotime($start_date); $end_timestamp = strtotime($end_date); $start_month = date('n', $start_timestamp); $start_year = date('Y', $start_timestamp); $end_month = date('n', $end_timestamp); $end_year = date('Y', $end_timestamp); if ($start_month === $end_month && $start_year === $end_year) { $start_day = date('j', $start_timestamp); $end_full = date_i18n('j F Y', $end_timestamp); return "Du " . $start_day . " au " . $end_full; } else { return "Du " . $start_formatted . " au " . $end_formatted; } } // === FONCTION POUR L'ARCHIVE DES ÉVÉNEMENTS === function gram_event_get_enhanced_archive_meta() { $post_id = get_the_ID(); // Récupération des métadonnées $start_date = get_post_meta($post_id, 'event_start_date', true); $end_date = get_post_meta($post_id, 'event_end_date', true); $vernissage_date = get_post_meta($post_id, 'vernissage_date', true); $vernissage_time = get_post_meta($post_id, 'vernissage_time', true); $price = get_post_meta($post_id, 'event_price', true); // Récupération des taxonomies $locations = get_the_terms($post_id, 'location'); $organizers = get_the_terms($post_id, 'organizer'); $html = '
'; // === BLOC DATES === if ($start_date) { $html .= '
'; $dates_detail = gram_event_get_date_details($start_date, $end_date); $html .= '
'; $html .= '📅'; $html .= '' . esc_html($dates_detail) . ''; $html .= '
'; // Vernissage si présent if ($vernissage_date) { $vernissage_str = gram_event_format_date($vernissage_date); if ($vernissage_time) { $vernissage_str .= ' à ' . gram_event_format_time($vernissage_time); } $html .= '
'; $html .= '🍷'; $html .= 'Vernissage : ' . $vernissage_str . ''; $html .= '
'; } $html .= '
'; } // === BLOC LIEU === if ($locations && !is_wp_error($locations)) { $html .= '
'; $location = $locations[0]; $address = get_term_meta($location->term_id, 'location_address', true); $html .= '
'; $html .= '📍'; $html .= '
'; $html .= '' . esc_html($location->name) . ''; if ($address) { $html .= '' . esc_html($address) . ''; } $html .= '
'; $html .= '
'; $html .= '
'; } // === BLOC ORGANISATEUR === if ($organizers && !is_wp_error($organizers)) { $html .= '
'; $organizer = $organizers[0]; $html .= '
'; $html .= '👥'; $html .= 'Organisé par ' . esc_html($organizer->name) . ''; $html .= '
'; $html .= '
'; } // === BLOC PRIX === if ($price) { $html .= '
'; $html .= '💶'; $html .= '' . esc_html($price) . ''; $html .= '
'; } $html .= '
'; return $html; } // === FONCTION POUR LES PAGES INDIVIDUELLES (CONSERVÉE DE L'ORIGINAL) === function gram_event_get_sidebar_content() { $post_id = get_the_ID(); // Récupération des métadonnées $start_date = get_post_meta($post_id, 'event_start_date', true); $end_date = get_post_meta($post_id, 'event_end_date', true); $vernissage_date = get_post_meta($post_id, 'vernissage_date', true); $vernissage_time = get_post_meta($post_id, 'vernissage_time', true); $finissage_date = get_post_meta($post_id, 'finissage_date', true); $finissage_time = get_post_meta($post_id, 'finissage_time', true); $price = get_post_meta($post_id, 'event_price', true); // Récupération des taxonomies $locations = get_the_terms($post_id, 'location'); $organizers = get_the_terms($post_id, 'organizer'); $sidebar = '
'; // === BLOC DATES PRINCIPALES === $sidebar .= '
'; $sidebar .= '

Dates de l\'événement

'; if ($start_date) { $dates_detail = gram_event_get_date_details($start_date, $end_date); $sidebar .= '
'; $sidebar .= '

' . esc_html($dates_detail) . '

'; if ($end_date && $end_date !== $start_date) { $sidebar .= '
'; $sidebar .= '

Début : ' . gram_event_format_date($start_date) . '

'; $sidebar .= '

Fin : ' . gram_event_format_date($end_date) . '

'; $sidebar .= '
'; } $sidebar .= '
'; } $sidebar .= '
'; // === BLOC VERNISSAGE ET FINISSAGE === if ($vernissage_date || $finissage_date) { $sidebar .= '
'; $sidebar .= '

Événements spéciaux

'; if ($vernissage_date) { $sidebar .= '
'; $sidebar .= '
'; $sidebar .= '🍷'; $sidebar .= 'Vernissage'; $sidebar .= '
'; $sidebar .= '
'; $sidebar .= '

' . gram_event_format_date($vernissage_date) . '

'; if ($vernissage_time) { $sidebar .= '

à ' . gram_event_format_time($vernissage_time) . '

'; } $sidebar .= '
'; $sidebar .= '
'; } if ($finissage_date) { $sidebar .= '
'; $sidebar .= '
'; $sidebar .= '🎉'; $sidebar .= 'Finissage'; $sidebar .= '
'; $sidebar .= '
'; $sidebar .= '

' . gram_event_format_date($finissage_date) . '

'; if ($finissage_time) { $sidebar .= '

à ' . gram_event_format_time($finissage_time) . '

'; } $sidebar .= '
'; $sidebar .= '
'; } $sidebar .= '
'; } // === BLOC PRIX === if ($price) { $sidebar .= '
'; $sidebar .= '

Tarifs

'; $sidebar .= '
'; $sidebar .= '

' . esc_html($price) . '

'; $sidebar .= '
'; $sidebar .= '
'; } // === BLOC LIEUX AVEC LOGOS === if ($locations && !is_wp_error($locations)) { $sidebar .= '
'; $sidebar .= '

Lieu

'; foreach ($locations as $location) { $address = get_term_meta($location->term_id, 'location_address', true); $website = get_term_meta($location->term_id, 'location_website', true); // Récupération du logo du lieu $logo_id = get_term_meta($location->term_id, 'location_logo_id', true); $logo_url = $logo_id ? wp_get_attachment_url($logo_id) : ''; $sidebar .= '
'; // Affichage du logo if ($logo_url) { $sidebar .= '
'; $sidebar .= ''; $sidebar .= '
'; } $sidebar .= '

' . esc_html($location->name) . '

'; if ($address) { $sidebar .= '

'; $sidebar .= ' ' . esc_html($address); $sidebar .= '

'; } if ($website) { $sidebar .= '

'; $sidebar .= ''; $sidebar .= ' Site web'; $sidebar .= ''; $sidebar .= '

'; } $sidebar .= '
'; } $sidebar .= '
'; } // === BLOC ORGANISATEURS AVEC LOGOS ET SITE WEB === if ($organizers && !is_wp_error($organizers)) { $sidebar .= '
'; $sidebar .= '

Organisateur

'; foreach ($organizers as $organizer) { $phone = get_term_meta($organizer->term_id, 'organizer_phone', true); $email = get_term_meta($organizer->term_id, 'organizer_email', true); $website = get_term_meta($organizer->term_id, 'organizer_website', true); // Récupération du logo de l'organisateur $logo_id = get_term_meta($organizer->term_id, 'organizer_logo_id', true); $logo_url = $logo_id ? wp_get_attachment_url($logo_id) : ''; $sidebar .= '
'; // Affichage du logo if ($logo_url) { $sidebar .= '
'; $sidebar .= ''; $sidebar .= '
'; } $sidebar .= '

' . esc_html($organizer->name) . '

'; // Site web de l'organisateur if ($website) { $sidebar .= '

'; $sidebar .= ''; $sidebar .= ' Site web'; $sidebar .= ''; $sidebar .= '

'; } if ($phone) { $sidebar .= '

'; $sidebar .= ' ' . esc_html($phone); $sidebar .= '

'; } if ($email) { $sidebar .= '

'; $sidebar .= ''; $sidebar .= ' ' . esc_html($email); $sidebar .= ''; $sidebar .= '

'; } $sidebar .= '
'; } $sidebar .= '
'; } $sidebar .= '
'; return $sidebar; } // === FONCTION PRINCIPALE DE ROUTAGE === function gram_event_display_details($content) { // Pour les archives d'événements if (is_post_type_archive('event') || (get_post_type() === 'event' && !is_singular())) { return $content . gram_event_get_enhanced_archive_meta(); } // Pour les pages individuelles d'événements if (is_singular('event')) { $sidebar_content = gram_event_get_sidebar_content(); $output = '
'; $output .= '
'; $output .= $content; $output .= '
'; $output .= $sidebar_content; $output .= '
'; return $output; } return $content; } add_filter('the_content', 'gram_event_display_details'); // DEBUG CORRIGÉ pour identifier le problème d'archive function gram_event_debug_info($content) { // Pour les pages individuelles d'événements if (is_singular('event')) { $debug = '
'; $debug .= 'DEBUG PAGE INDIVIDUELLE:
'; $debug .= 'Post Type: ' . get_post_type() . '
'; $debug .= 'Is Singular: OUI
'; $start_date = get_post_meta(get_the_ID(), 'event_start_date', true); $debug .= 'Date début: ' . ($start_date ? $start_date : 'VIDE') . '
'; $locations = get_the_terms(get_the_ID(), 'location'); $debug .= 'Lieu: ' . ($locations && !is_wp_error($locations) ? $locations[0]->name : 'VIDE') . '
'; $debug .= '
'; return $content . $debug; } // Pour l'archive d'événements if (is_post_type_archive('event')) { $debug = '
'; $debug .= 'DEBUG ARCHIVE:
'; $debug .= 'Is Archive: OUI
'; $debug .= 'Post Type Archive: event
'; $debug .= 'Current Post in Loop: ' . get_post_type() . '
'; $debug .= '
'; return $content . $debug; } return $content; } add_filter('the_content', 'gram_event_debug_info', 999); // DEBUG UNIVERSEL - à ajouter à la fin de display.php function gram_event_footer_debug() { echo '
'; echo '🔍 DEBUG GRAM:
'; echo 'Page: ' . $_SERVER['REQUEST_URI'] . '
'; echo 'Is Archive: ' . (is_post_type_archive('event') ? 'OUI' : 'NON') . '
'; echo 'Is Singular: ' . (is_singular('event') ? 'OUI' : 'NON') . '
'; if (is_post_type_archive('event')) { global $wp_query; echo 'Found Posts: ' . $wp_query->found_posts . '
'; echo 'Post Count: ' . $wp_query->post_count . '
'; echo 'Template: ' . get_option('template') . '
'; } echo '
'; } add_action('wp_footer', 'gram_event_footer_debug'); ?>