From 5035f7f2caac8f6739cc06d17fb20af92c2d80c0 Mon Sep 17 00:00:00 2001 From: Matthew Bernhardt Date: Thu, 15 Jun 2023 17:36:06 -0400 Subject: [PATCH] Quick refactor of page-exhibits-feed --- .../templates/page-exhibits-feed.php | 244 ++++++++---------- 1 file changed, 110 insertions(+), 134 deletions(-) diff --git a/web/app/themes/mitlib-child/templates/page-exhibits-feed.php b/web/app/themes/mitlib-child/templates/page-exhibits-feed.php index d25477b0..2714ab50 100644 --- a/web/app/themes/mitlib-child/templates/page-exhibits-feed.php +++ b/web/app/themes/mitlib-child/templates/page-exhibits-feed.php @@ -8,166 +8,144 @@ namespace Mitlib\Child; -get_header( 'child' ); +// Define the queries which will populate the three display sections. +$current = array( + 'posts_per_page' => 10, + 'ignore_sticky_posts' => false, + 'post_type' => 'exhibits', // Only query exhibits. + 'meta_key' => 'start_date', // Load up the event_date meta. + 'orderby' => 'start_date', + 'order' => 'DESC', // Descending, so later events first. + 'meta_query' => array( // The meta_query is an array of query items. + array( + 'key' => 'start_date', // Which meta to query. + 'value' => gmdate( 'Y-m-d' ), // Value for comparison. + 'compare' => '<=', // Method of comparison. + 'type' => 'DATE', + ), + array( + 'relation' => 'OR', + array( + 'key' => 'end_date', // Which meta to query. + 'value' => gmdate( 'Y-m-d' ), // Value for comparison. + 'compare' => '>=', // Method of comparison. + 'type' => 'DATE', + ), + array( + 'key' => 'end_date', // Which meta to query. + 'value' => '', // Value for comparison. + 'compare' => '=', // Method of comparison. + 'type' => 'CHAR', + ), + ), + ), // End meta_query array. +); // End current query. + +$future = array( + 'post_type' => 'exhibits', // Only query exhibits. + 'meta_key' => 'start_date', // Load up the event_date meta. + 'orderby' => 'start_date', + 'order' => 'ASC', + 'posts_per_page' => 10, // Descending, so later events first. + 'meta_query' => array( + array( + 'key' => 'start_date', // Which meta to query. + 'value' => gmdate( 'Y-m-d' ), // Value for comparison. + 'compare' => '>', // Method of comparison. + 'type' => 'DATE', + ), // The meta_query is an array of query items. + ), // End meta_query array. +); // End future query. + +$past = array( + 'post_type' => 'exhibits', // Only query events. + 'meta_key' => 'end_date', // Load up the event_date meta. + 'orderby' => 'end_date', + 'order' => 'DESC', // Descending, so later events first. + 'posts_per_page' => 5, + 'meta_query' => array( + array( + 'key' => 'end_date', // Which meta to query. + 'value' => gmdate( 'Y-m-d' ), // Value for comparison. + 'compare' => '<', // Method of comparison. + 'type' => 'DATE', + ), // The meta_query is an array of query items. + ), // End meta_query array. +); // End past query. + ?> - + + + -
+
-
+
-
- - 10, - 'ignore_sticky_posts' => false, - 'post_type' => 'exhibits', // Only query exhibits. - 'meta_key' => 'start_date', // Load up the event_date meta. - 'orderby' => 'start_date', - 'order' => 'DESC', // Descending, so later events first. - 'meta_query' => array( // The meta_query is an array of query items. - array( - 'key' => 'start_date', // Which meta to query. - 'value' => gmdate( 'Y-m-d' ), // Value for comparison. - 'compare' => '<=', // Method of comparison. - 'type' => 'DATE', - ), - array( - 'relation' => 'OR', - array( - 'key' => 'end_date', // Which meta to query. - 'value' => gmdate( 'Y-m-d' ), // Value for comparison. - 'compare' => '>=', // Method of comparison. - 'type' => 'DATE', - ), - array( - 'key' => 'end_date', // Which meta to query. - 'value' => '', // Value for comparison. - 'compare' => '=', // Method of comparison. - 'type' => 'CHAR', - ), - ), - ), // End meta_query array. - ) // End array. - ); // Close WP_Query constructor call. - ?> +
+ +

Current Exhibits

- + have_posts() ) : - while ( $current_query->have_posts() ) : + if ( $current_query->have_posts() ) { + while ( $current_query->have_posts() ) { $current_query->the_post(); // Loop for current exhibits. get_template_part( 'inc/exhibits-detail' ); + }; + wp_reset_postdata(); + } else { + echo '

There are no current exhibit announcements at this time. New exhibits are added throughout the year, so please check back.

'; + } + ?> - endwhile; - - wp_reset_postdata(); - - else : - ?> - -

- - -
- - + - - $future_query = new \WP_Query( - array( - 'post_type' => 'exhibits', // Only query exhibits. - 'meta_key' => 'start_date', // Load up the event_date meta. - 'orderby' => 'start_date', - 'order' => 'ASC', - 'posts_per_page' => 10, // Descending, so later events first. - 'meta_query' => array( - array( - 'key' => 'start_date', // Which meta to query. - 'value' => gmdate( 'Y-m-d' ), // Value for comparison. - 'compare' => '>', // Method of comparison. - 'type' => 'DATE', - ), // The meta_query is an array of query items. - ), // End meta_query array. - ) // End array. - ); // Close WP_Query constructor call. - ?> -
- +

Upcoming Exhibits

- + have_posts() ) : - while ( $future_query->have_posts() ) : + if ( $future_query->have_posts() ) { + while ( $future_query->have_posts() ) { $future_query->the_post(); // Loop for future exhibits. get_template_part( 'inc/exhibits-detail' ); - - endwhile; - + }; wp_reset_postdata(); + } else { + echo '

There are no upcoming exhibit announcements at this time. New exhibits are added throughout the year, so please check back.

'; + } + ?> - else : - ?> - -

- - -
- - + - - - 'exhibits', // Only query events. - 'meta_key' => 'end_date', // Load up the event_date meta. - 'orderby' => 'end_date', - 'order' => 'DESC', // Descending, so later events first. - 'posts_per_page' => 5, - 'meta_query' => array( - array( - 'key' => 'end_date', // Which meta to query. - 'value' => gmdate( 'Y-m-d' ), // Value for comparison. - 'compare' => '<', // Method of comparison. - 'type' => 'DATE', - ), // The meta_query is an array of query items. - ), // End meta_query array. - ) // End array. - ); // Close WP_Query constructor call. - ?> + +
- +

Past Exhibits

- + have_posts() ) : + while ( $past_query->have_posts() ) { $past_query->the_post(); // Loop for events. get_template_part( 'inc/exhibits-detail' ); - - wp_reset_postdata(); // Restore global post data stomped by the_post(). - - endwhile; // End of the loop. + }; + wp_reset_postdata(); // Restore global post data stomped by the_post(). ?>
@@ -175,15 +153,13 @@ View all past exhibits - - - -
- - - -
- -
- + +
+ + + +
+ +
+