@@ -567,3 +567,141 @@ function ( $date ) use ( $post ) {
567567 }
568568}
569569
570+
571+ if ( ! function_exists ( 'se_fix_se_events_fse_archive_template ' ) ) {
572+ /**
573+ * Fix the template hierarchy for the SE Events FSE archive.
574+ *
575+ * @param array $templates The template hierarchy.
576+ *
577+ * @return array The modified template hierarchy.
578+ */
579+ function se_fix_se_events_fse_archive_template ( $ templates ) {
580+ if ( 'se-event-date ' === get_query_var ( 'post_type ' ) ) {
581+ // Create proper hierarchy: archive-se-events.html, then archive.html
582+ $ custom_hierarchy = array (
583+ 'archive-se-event.html ' ,
584+ 'archive.html ' ,
585+ );
586+
587+ return $ custom_hierarchy ;
588+ }
589+ return $ templates ;
590+ }
591+ }
592+
593+ // Filter to modify the body class for the event date archive.
594+ if ( ! function_exists ( 'se_modify_event_date_archive_body_class ' ) ) {
595+ /**
596+ * Modify the body class for the event date archive.
597+ *
598+ * @param array $classes The existing body classes.
599+ *
600+ * @return array The modified body classes.
601+ */
602+ function se_modify_event_date_archive_body_class ( $ classes ) {
603+ $ classes = array_map (
604+ function ( $ body_class ) {
605+ return 'post-type-archive-se-event-date ' === $ body_class ? 'post-type-archive-se-event ' : $ class ;
606+ },
607+ $ classes
608+ );
609+ return $ classes ;
610+ }
611+ }
612+
613+ // Modify the archive page title.
614+ if ( ! function_exists ( 'se_modify_event_date_archive_template_title ' ) ) {
615+ /**
616+ * Modify the archive page title for the event date archive.
617+ *
618+ * @param string $title The existing archive title.
619+ *
620+ * @return string The modified archive title.
621+ */
622+ function se_modify_event_date_archive_template_title ( $ title ) {
623+ if ( is_post_type_archive ( 'se-event-date ' ) ) {
624+ $ original_title = $ title ;
625+ // Get the se-event post type object to use its archive title
626+ $ post_type_obj = get_post_type_object ( 'se-event ' );
627+
628+ // If this is a post_typw archive, use the post type archive title.
629+ if ( is_post_type_archive () ) {
630+ $ title = apply_filters ( 'post_type_archive_title ' , $ post_type_obj ->labels ->name , 'se-event ' ); // phpcs:ignore
631+ $ prefix = _x ( 'Archives: ' , 'post type archive title prefix ' ); // phpcs:ignore
632+ } elseif ( is_tax () && $ post_type_obj ) {
633+ $ tax = get_taxonomy ( $ post_type_obj ->taxonomy );
634+ $ title = single_term_title ( '' , false );
635+ $ prefix = sprintf (
636+ /* translators: %s: Taxonomy singular name. */
637+ _x ( '%s: ' , 'taxonomy term archive title prefix ' ), // phpcs:ignore
638+ $ tax ->labels ->singular_name
639+ );
640+ } else {
641+ $ prefix = '' ;
642+ }
643+
644+ /**
645+ * Filters the archive title prefix.
646+ *
647+ * @since 5.5.0
648+ *
649+ * @param string $prefix Archive title prefix.
650+ */
651+ $ prefix = apply_filters ( 'get_the_archive_title_prefix ' , $ prefix ); // phpcs:ignore
652+ if ( $ prefix ) {
653+ $ title = sprintf (
654+ /* translators: 1: Title prefix. 2: Title. */
655+ _x ( '%1$s %2$s ' , 'archive title ' ), // phpcs:ignore
656+ $ prefix ,
657+ '<span> ' . $ title . '</span> '
658+ );
659+ }
660+ }
661+ return $ title ;
662+ }
663+ }
664+
665+
666+
667+ // Modify the page HTML title for the event date archive.
668+ if ( ! function_exists ( 'se_modify_event_date_archive_page_title ' ) ) {
669+ /**
670+ * Modify the page HTML title for the event date archive.
671+ *
672+ * @param string $title The existing page title.
673+ *
674+ * @return string The modified page title.
675+ */
676+ function se_modify_event_date_archive_page_title ( $ title ) {
677+ if ( is_post_type_archive ( 'se-event-date ' ) ) {
678+ $ event_post_type = get_post_type_object ( 'se-event ' );
679+ $ title = $ event_post_type ->labels ->name ;
680+ } elseif ( is_tax () ) {
681+ $ taxonomy = get_queried_object ();
682+ if ( $ taxonomy ) {
683+ $ title = $ taxonomy ->name ;
684+ }
685+ }
686+ return $ title ;
687+ }
688+ }
689+ /**
690+ * Ensure that legacy themes will call the se-event archive template.
691+ *
692+ * @since 2.0.0
693+ *
694+ * @param string $template The template file to use.
695+ *
696+ * @return string The modified template file.
697+ */
698+ function se_event_archive_template ( $ template ) {
699+ if ( is_post_type_archive ( 'se-event-date ' ) ) {
700+ // If the template is not set, use the default archive template.
701+ $ date_archive_template = locate_template ( 'archive-se-event.php ' );
702+ if ( $ date_archive_template ) {
703+ return $ date_archive_template ;
704+ }
705+ }
706+ return $ template ;
707+ }
0 commit comments