From 0b3c82ad7b08b73ab8665634767fe727e2dae195 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Thu, 30 Jul 2026 14:02:36 -0500 Subject: [PATCH] feat: identify continuous calendar segments --- includes/calendar-layout.php | 11 +++++++++++ templates/calendar.php | 13 +++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/calendar-layout.php b/includes/calendar-layout.php index 2494b72..d42dac9 100644 --- a/includes/calendar-layout.php +++ b/includes/calendar-layout.php @@ -81,6 +81,17 @@ function aa_events_occurrence_intersects_range( array $occurrence, DateTimeImmut return null !== $occurrence_start && null !== $occurrence_end && $occurrence_end >= $occurrence_start && $end >= $start && $occurrence_start <= $end && $occurrence_end >= $start; } +/** + * Build a stable key for an event occurrence within a calendar render. + * + * @param mixed $post_id Event post ID. + * @param mixed $occurrence_index Zero-based occurrence index for the event. + * @return string + */ +function aa_events_calendar_occurrence_key( $post_id, $occurrence_index ) { + return (int) $post_id . '-' . (int) $occurrence_index; +} + /** * Clip an occurrence to a month and split it at week boundaries. * diff --git a/templates/calendar.php b/templates/calendar.php index 46d271d..9b55e03 100644 --- a/templates/calendar.php +++ b/templates/calendar.php @@ -117,14 +117,15 @@ $events = new WP_Query( foreach ( $events->posts as $event_id ) { $event_title = get_the_title( $event_id ); $event_permalink = get_permalink( $event_id ); - foreach ( aa_events_get_occurrences( $event_id ) as $occurrence ) { + foreach ( aa_events_get_occurrences( $event_id ) as $occurrence_index => $occurrence ) { if ( ! is_array( $occurrence ) || ! aa_events_occurrence_intersects_range( $occurrence, $month['month_start'], $month['month_end'] ) ) { continue; } - $occurrence['post_id'] = (int) $event_id; - $occurrence['title'] = $event_title; - $occurrence['permalink'] = $event_permalink; - $calendar_occurrences[] = $occurrence; + $occurrence['post_id'] = (int) $event_id; + $occurrence['title'] = $event_title; + $occurrence['permalink'] = $event_permalink; + $occurrence['calendar_occurrence_key'] = aa_events_calendar_occurrence_key( $event_id, $occurrence_index ); + $calendar_occurrences[] = $occurrence; } } @@ -211,7 +212,7 @@ $calendar_url = static function ( DateTimeImmutable $date ) use ( $calendar /* translators: 1: event title, 2: complete event date and time range. */ $event_label = sprintf( __( '%1$s: %2$s', 'aa-events' ), $segment['title'], aa_events_format_occurrence( $segment ) ); ?> - +