Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 29, 2015 12:39
Show Gist options
  • Save robneu/7671867 to your computer and use it in GitHub Desktop.
Save robneu/7671867 to your computer and use it in GitHub Desktop.
Display some information about a podcast's air date using Genesis.
<?php
add_action( 'genesis_before_content', 'wpbacon_podcast_date_info' );
/**
* Displays information about the podcast's air date including the date, time,
* and whether or not it's already aired.
*
* @since 2.0.0
*/
function wpbacon_podcast_date_info() {
// Do nothing if the post has no air date or air time.
if ( ! get_field('air_date') || ! get_field( 'air_time' ) ) {
return;
}
// Get the Podcast's air date.
$date = DateTime::createFromFormat( 'mdY', get_field( 'air_date' ) ) ;
// Format the date for display.
$air_date = $date->format( 'F dS, Y' );
$air_time = get_field( 'air_time' );
// Set some air text.
$air_text = __( 'Airs Live at ', 'wpbacon' );
// Set different air text for already-aired episodes.
if ( current_time( 'timestamp', 0 ) > $date->format( 'U' ) ) {
$air_text = __( 'Aired Live at ', 'wpbacon' );
}
// Display the air date and time.
echo '<h2 class="air-date">' . $air_text . esc_attr( $air_time ) . ' on ' . esc_attr( $air_date ) . '</h2>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment