Created
March 22, 2016 18:56
-
-
Save jsoningram/6bc033beebe70b3b619f 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 | |
$args = array( | |
'orderby' => 'id', | |
'hide_empty' => false, | |
'parent' => 0 | |
); | |
$terms = get_terms( 'category', $args ); | |
$cats = get_terms( 'category', $args ); | |
$year = date( 'Y' ); | |
$all = [ | |
'term_id' => '0', | |
'name' => 'All', | |
'slug' => 'all' | |
]; | |
$all = (object) $all; | |
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { | |
array_unshift( $terms, $all ); | |
$program_guide_cats = ''; | |
foreach ($cats as $cat ) { | |
$program_guide_cats .= $cat->name . ','; | |
} | |
if ( is_page( 'watch-live' ) ) { | |
$program_guide_cats = 'live'; | |
} | |
if ( ! is_page( 'watch-live' ) ) { | |
echo '<ul class="program-guide-menu">'; | |
foreach ( $terms as $term ) { | |
if ( 'all' == $term->slug ) { | |
echo '<li class="active-category">'; | |
} else { | |
echo '<li>'; | |
} | |
echo '<a href="#' . esc_attr( $term->slug ) . '"' | |
. 'class="' . esc_attr( $term->slug ) . '"' | |
. 'data-category="' . esc_attr( $term->slug ) . '"' | |
. 'title="' . esc_attr( $term->name ) . '">' | |
. esc_html( $term->name ) | |
. '</a>' | |
. '</li>' | |
; | |
} | |
echo '</ul>'; | |
} | |
} | |
echo '<div id="accordion">'; | |
$months = [ 1,2,3,4,5,6,7,8,9,10,11,12 ]; | |
$active_months = []; | |
foreach ( $months as $month ) { | |
$i = 0; | |
$queryargs = [ | |
'category_name' => $program_guide_cats, | |
'posts_per_page' => -1, | |
'date_query' => [ 'year' => $year, 'month' => $month ], | |
'post_type' => 'video', | |
'ignore_sticky_posts' => true, | |
'order' => 'ASC', | |
'orderby' => 'date', | |
'no_found_rows' => true, | |
'update_post_meta_cache' => false | |
]; | |
$query = new WP_Query( $queryargs ); | |
$month_name = strtolower( date( 'M', mktime( 0, 0, 0, $month, 10 ) ) ); | |
$full_month = strtolower( date( 'F', mktime( 0, 0, 0, $month, 10 ) ) ); | |
$active = ( $full_month == strtolower( date( 'F' ) ) ) ? 'current-month ' : ''; | |
echo '<h3 class="' . $active . $month_name . '-heading">' | |
. esc_html( $month_name ) . ' ' . $year | |
. '</h3>' | |
. '<div class="' . $month_name . '-contents accordion-contents">' | |
; | |
if ( $query->have_posts() ) { | |
while ( $query->have_posts() ) { $query->the_post(); | |
$category = get_the_category(); | |
$category_slug = esc_html( $category[0]->slug ); | |
$venue = esc_html( get_post_meta( $post->ID, 'wpcf-venue', true ) ); | |
$start_time = intval( get_post_meta( $post->ID, 'wpcf-start-time', true ) ); | |
$meta_date = date( 'Y-m-d', $start_time ); | |
$num_month = intval( date('n', $start_time ) ); | |
$pub_month = strtolower( date('M', $start_time ) ); | |
$day = date( 'j', $start_time ); | |
$mil = date( 'H', $start_time ); | |
$time = date( 'g:i', $start_time ); | |
$exact_time = date( 'g:i:s', $start_time ); | |
$pub_date = strval( $meta_date . ' ' . $exact_time ); | |
$meridiem = ( $mil > 11 ) ? 'pm' : 'am'; | |
$post_index = $query->post_count - 1; | |
$last_post = ( $post_index == $i ) ? ' last-video' : ''; | |
$video_url = remove_protocol( esc_url( get_post_meta( $post->ID, 'wpcf-video-url', true ) ) ); | |
wp_update_post( [ 'ID' => $post->ID, 'post_date' => $pub_date ] ); | |
$active_dates[] = $meta_date; | |
$active_dates = array_unique( $active_dates, SORT_STRING ); | |
$active_dates = array_values($active_dates); | |
if ( $num_month == $month ) { | |
echo '<h4 class="' . $category_slug . ' ' . $pub_month . '-sub-heading subheading"' | |
. 'data-date="' . $meta_date . '">' | |
. $pub_month . ' ' . $day | |
. '</h4>' | |
; | |
echo '<ul class="' . $category_slug . '"' | |
. 'data-date="' . $meta_date . '">' | |
; | |
echo '<li class="' . $category_slug . $last_post . '">' | |
. '<span class="video-title">' . esc_html( get_the_title() ) . '</span>' | |
. '<span class="video-venue">' . esc_html( $venue ) . '</span>' | |
; | |
if ( '00' != $mil && 'live' == $category_slug ) { | |
echo '<span class="start-time">Begins at ' . $time . $meridiem . ' ET</span>'; | |
} | |
if ( '' != $video_url ) { | |
echo '<span><a class="video-url" src="' . $video_url . '">Click to watch</a></span>'; | |
} | |
echo '</li></ul>'; | |
$i++; | |
} | |
} | |
wp_reset_postdata(); | |
} else { | |
$category_classes = strtolower( str_replace( ',', ' ', $program_guide_cats ) ); | |
echo '<ul><li class="' . $category_classes | |
. ' all no-videos">There are no videos scheduled for this month yet</li></ul>' | |
; | |
} | |
echo '</div><!-- /.accordion-contents -->'; | |
} | |
echo '</div><!-- /#accordion -->'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment