-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcode--film-showtimes.php
55 lines (40 loc) · 1.5 KB
/
shortcode--film-showtimes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
function showtimes_function($atts = [], $tag = '') {
$output = '';
$output .= '<h4 class="screenings--title">Showtimes</h4>';
$post_id = get_the_ID();
$screenings = get_field('screenings', $post_id);
$screenings_unix = array();
if ($screenings) {
foreach ($screenings as $key=>$thisScreening) {
$thisScreeningDate = $thisScreening['screening_date'];
$thisScreeningTime = $thisScreening['screening_time'];
$thisScreeningDateTime = $thisScreeningDate . ' ' . $thisScreeningTime;
$unixtime = strtotime($thisScreeningDateTime);
array_push($screenings_unix, $unixtime);
}
sort($screenings_unix);
$output .= '<table class="screenings"><tr><td>';
$lastScreening = 0;
foreach ($screenings_unix as &$thisScreening) {
$lastScreening_date = date('m/d', $lastScreening);
$thisScreening_date = date('m/d', $thisScreening);
// $output .= '<h6>' . $lastScreening_date . ' ' . $thisScreening_date . '</h6>';
if ( $lastScreening_date != $thisScreening_date ) :
if ($lastScreening != 0) :
$output .= '</td></tr><tr><td>';
endif;
$output .= date('l, F j: ', $thisScreening) . '</td><td>' . date('g:i a', $thisScreening);
else :
$output .= ', ' . date('g:i a', $thisScreening);
endif;
$lastScreening = $thisScreening;
}
$output .= '</td></tr></table>';
}
else {
$output .= '<p>TBA</p>';
}
return $output;
}
add_shortcode('film_showtimes', 'showtimes_function');