Created
April 20, 2015 10:14
-
-
Save michaelschofield/59e66738d0eba6b51cff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( $the_query->have_posts() ) : ?> | |
<header class="page-header"> | |
<?php | |
the_archive_title( '<h1 class="page-title">', '</h1>' ); | |
the_archive_description( '<div class="taxonomy-description">', '</div>' ); | |
?> | |
</header><!-- .page-header --> | |
<?php | |
// Start the Loop. | |
while ( $the_query->have_posts() ) : $the_query->the_post(); | |
// Once within the loop, we can create fetch information from the post's custom fields | |
// Some of this is contingent on whether our event is All Day or Multi-Day, | |
// so we first need to declare variables for these values. In PHP, if you | |
// want to pass a value between conditions (if / then statements), they need | |
// to be declared outside of those conditions first. So even though we | |
// don't know yet if an event is All Day or Multi-Day, we just have to | |
// establish a starting point. Let's assume that the default is that | |
// events are neither All Day or Multi-Day. | |
$allday = false; | |
$multiday = false; | |
// The reality as to whether these variables are true or not is | |
// stored is stored in the checkboxes, which I happened to call | |
// 'scheduling options'. So let's get that first: | |
$scheduling_options = get_post_meta( get_the_ID(), 'scheduling_options', true); | |
// All events have a start day, so let's get that | |
$start_date = get_post_meta( get_the_ID(), 'advwp_start_date', true ); | |
// The full picture of what is the beginning and end of an event | |
// isn't just the day - it's the time. To be able to sort and organize events | |
// by start time, especially when they are in the same day, we need to | |
// have a value that is both the day of the event and the time of the event. | |
// We don't know that just yet, but let's create those variables and set | |
// their default value as just the day of the event - which we already have in | |
// $start_date. | |
$start = $start_date; | |
$end = $start_date; | |
// Now, based on the value of our $scheduling_options, we will figure out | |
// whether custom fields exist for start and end time, and set those. This | |
// begins with the condition that there are NO scheduling_options, meaning | |
// neither of the boxes were checked - or the default state of the event. | |
// The !$scheduling_options means "No value for $scheduling_options". | |
if ( !$scheduling_options ) { | |
$start_time = get_post_meta( get_the_ID(), 'advwp_start_time', true); | |
$end_time = get_post_meta( get_the_ID(), 'advwp_end_time', true ); | |
// Now with a $start_time and $end_time, we can update our | |
// $start and $end variables to include day and time | |
$start = $start_date . $start_time; | |
$end = $start_date . $end_time; | |
} else { // However, if there ARE $scheduling_options | |
// If the "All Day" box was checked, let's update | |
// $allday to true | |
if ( in_array( "allday", $scheduling_options) ) : | |
$allday = true; | |
else : // Otherwise, update our $end variable | |
$end = get_post_meta( get_the_ID(), 'advwp_end_date', true ) . get_post_meta( get_the_ID(), 'advwp_end_time', true); | |
endif; | |
// If the "Multi-day" box was checked ... | |
if ( in_array( "multiday", $scheduling_options) ) : | |
$multiday = true; | |
$start = $start_date; | |
$end = get_post_meta( get_the_ID(), 'advwp_end_date', true); | |
endif; | |
} | |
?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<?php | |
// Post thumbnail. | |
twentyfifteen_post_thumbnail(); | |
?> | |
<header class="entry-header"> | |
<?php | |
if ( is_single() ) : | |
the_title( '<h1 class="entry-title">', '</h1>' ); | |
else : | |
the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); | |
endif; | |
?> | |
</header><!-- .entry-header --> | |
<div class="entry-content"> | |
<?php | |
// To ensure that we are successfully fetching our custom | |
// fields, we'll 'echo' - or print -- the variables we stored | |
// above. | |
echo date( 'l, F jS', strtotime($start_date) ) . ' from ' . date( 'h:i a', $start_time ) . ' - ' . date( 'h:i a', $end_time ) . '<br>'; | |
the_content(); | |
wp_link_pages( array( | |
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>', | |
'after' => '</div>', | |
'link_before' => '<span>', | |
'link_after' => '</span>', | |
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%', | |
'separator' => '<span class="screen-reader-text">, </span>', | |
) ); | |
?> | |
</div><!-- .entry-content --> | |
<?php | |
// Author bio. | |
if ( is_single() && get_the_author_meta( 'description' ) ) : | |
get_template_part( 'author-bio' ); | |
endif; | |
?> | |
<footer class="entry-footer"> | |
</footer><!-- .entry-footer --> | |
</article><!-- #post-## --> | |
<?php | |
// End the loop. | |
endwhile; | |
// Previous/next page navigation. | |
the_posts_pagination( array( | |
'prev_text' => __( 'Previous page', 'twentyfifteen' ), | |
'next_text' => __( 'Next page', 'twentyfifteen' ), | |
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>', | |
) ); | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment