Affichage des dates : année seule pour les Ouvrages, plage pour les séminaires

This commit is contained in:
2026-05-28 18:27:05 +02:00
parent c1cad3b044
commit 369b882693
2 changed files with 71 additions and 13 deletions

View File

@@ -1,14 +1,15 @@
<?php
/**
* Format a Pods datetime string (e.g. "2026-01-17 00:00:00") into natural French/English.
* Shows time only if not midnight.
* Format a Pods datetime string (e.g. "2026-01-17 00:00:00") via date_i18n.
* Default format is "j F Y" (full month name, FR/EN per WP locale).
* Returns empty string for null/empty/"0000-00-00..." inputs.
*/
function thalim_format_date($raw, $lang = 'fr') {
function thalim_format_date($raw, $lang = 'fr', $format = 'j F Y') {
if (!$raw || str_starts_with($raw, '0000-00-00')) return '';
$ts = strtotime($raw);
if ($ts === false || $ts < 0) return '';
return date_i18n('j F Y', $ts);
return date_i18n($format, $ts);
}
/**
@@ -90,6 +91,15 @@ function thalim_get_single_data($post_id) {
if ($ts_debut) $data['date_debut_ymd'] = date('Y-m-d', $ts_debut);
if ($ts_fin) $data['date_fin_ymd'] = date('Y-m-d', $ts_fin);
// Ouvrages (cat 15): override display to year only — raw timestamps and
// *_ymd fields stay full-precision so sorting/filtering on index pages
// (`thalim_event_date_order`) keeps working.
if (in_array(15, wp_get_post_categories($post_id), true)) {
$data['date_de_debut'] = thalim_format_date($raw_debut, $lang, 'Y');
$data['date_de_fin'] = thalim_format_date($raw_fin, $lang, 'Y');
$data['datetime'] = thalim_format_date(get_post_meta($post_id, 'datetime', true), $lang, 'Y');
}
// --- External links (up to 3) ---
for ($i = 1; $i <= 3; $i++) {
$url = get_post_meta($post_id, 'lien_externe_' . $i, true);