Skip to content

Commit

Permalink
Quick refactor of page-exhibits-feed
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernhardt committed Jul 7, 2023
1 parent fea17c3 commit a99f431
Showing 1 changed file with 110 additions and 134 deletions.
244 changes: 110 additions & 134 deletions web/app/themes/mitlib-child/templates/page-exhibits-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,182 +8,158 @@

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.

?>

<?php get_template_part( 'inc/breadcrumbs', 'child' ); ?>
<?php get_header( 'child' ); ?>

<?php get_template_part( 'inc/breadcrumbs', 'child' ); ?>

<div id="stage" class="inner" role="main">
<div id="stage" class="inner" role="main">

<?php get_template_part( 'inc/title-banner' ); ?>

<div id="content" class="content has-sidebar">
<div id="content" class="content has-sidebar">

<div class="main-content">

<?php

$current_query = new \WP_Query(
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 array.
); // Close WP_Query constructor call.
?>
<div class="main-content">

<?php $current_query = new \WP_Query( $current ); ?>

<div class="exhibits-feed-section">

<h3 class="title-sub">Current Exhibits</h3>

<?php
if ( $current_query->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 '<p>There are no current exhibit announcements at this time. New exhibits are added throughout the year, so please check back.</p>';
}
?>

endwhile;

wp_reset_postdata();

else :
?>

<p><?php esc_html_e( 'There are no current exhibit announcements at this time. New exhibits are added throughout the year, so please check back.' ); ?></p>

<?php endif; ?>

</div>

<!-- END OF CURRENT EXHIBITS LOOP -->

<!-- END OF CURRENT EXHIBITS LOOP -->

<?php
<?php $future_query = new \WP_Query( $future ); ?>

$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.
?>

<div class="exhibits-feed-section">

<h3 class="title-sub">Upcoming Exhibits</h3>

<?php
if ( $future_query->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 '<p>There are no upcoming exhibit announcements at this time. New exhibits are added throughout the year, so please check back.</p>';
}
?>

else :
?>

<p><?php esc_html_e( 'There are no upcoming exhibit announcements at this time. New exhibits are added throughout the year, so please check back.' ); ?></p>

<?php endif; ?>

</div>



<!-- END OF UPCOMING EXHIBITS LOOP -->


<?php

$past_query = new \WP_Query(
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 array.
); // Close WP_Query constructor call.
?>

<?php $past_query = new \WP_Query( $past ); ?>

<div class="exhibits-feed-section">

<h3 class="title-sub">Past Exhibits</h3>

<?php
while ( $past_query->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().
?>

</div>

<a class="button-secondary exhibits-button" href="/exhibits/past-exhibits/">View all past exhibits</a>

<!-- END OF PAST EXHIBITS LOOP -->



</div> <!-- main-content -->

<?php get_sidebar(); ?>

</div> <!-- content -->

</div> <!-- stage -->


</div> <!-- .main-content -->

<?php get_sidebar(); ?>

</div> <!-- #content -->

</div> <!-- #stage -->

<?php get_footer(); ?>

0 comments on commit a99f431

Please sign in to comment.