Last active
December 29, 2015 12:39
-
-
Save robneu/7671867 to your computer and use it in GitHub Desktop.
Display some information about a podcast's air date using Genesis.
This file contains hidden or 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 | |
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