-
Notifications
You must be signed in to change notification settings - Fork 13
/
events.php
250 lines (225 loc) · 10.8 KB
/
events.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/*
Template Name:events
*/
?>
<?php get_header(); ?>
<div class="showcase-wrapper">
<div class="container-fluid">
<?php custom_breadcrumbs(); ?>
</div>
<?php
/* Check today's date and find events that start on or before today and end on or after today. */
$today = date('Ymd');
$args = array(
'post_type' => 'obf-events',
'meta_query' => array(
array(
'key' => 'start_date',
'compare' => '<=',
'value' => $today,
),
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $today,
)
),
'meta_key' => 'start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
$ongoing_events = new WP_Query( $args );
/*Show ongoing events section only if there are current events */
if ( $ongoing_events->have_posts() ) : ?>
<div class="ongoing-events">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="ongoing-events-head">
<h1>Ongoing Events</h1>
</div>
</div>
</div>
<?php while ( $ongoing_events->have_posts() ) : $ongoing_events->the_post(); ?>
<div class="card container mb-4">
<div class="card-data container-grid">
<div class="card-img">
<?php the_post_thumbnail(); ?>
</div>
<div class="card-body">
<h2 class="card-title">
<?php $event_url = get_post_meta( get_the_ID(), 'event_url', true ); ?>
<?php if($event_url) : { ?>
<a href="<?php echo $event_url; ?>" target="_blank">
<?php the_title(); ?></a>
<?php } else : { ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
<?php } endif; ?>
</h2>
<p class="card-text card-date"><i class="fas fa-calendar-day fa-lg"></i>
<?php $custom_start_date = get_field('start_date', false, false);
$custom_start_date = new DateTime($custom_start_date);
$custom_end_date = get_field('end_date', false, false);
$custom_end_date = new DateTime($custom_end_date);
?>
<?php echo $custom_start_date->format('Y-m-d'); ?> to
<?php echo $custom_end_date->format('Y-m-d'); ?>
</p>
<?php if( get_field('location') ) : ?>
<p class="card-text card-location"><i class="fas fa-map-marked-alt"></i>
<?php the_field('location'); ?>
</p>
<?php endif; ?>
</div>
</div>
<div class="card-footer card-info">
<?php if ( has_excerpt() ) : the_excerpt();
else : the_content();
endif; ?>
</div>
</div>
<?php endwhile; else : ?>
<p>
<?php __('Sorry, there are no current events and conferences. '); ?>
</p>
<?php endif; wp_reset_postdata(); ?>
</div>
</div>
<?php
/* Check today's date and find events that start after today. that is in the future. */
$today = date('Ymd');
$args = array(
'post_type' => 'obf-events',
'meta_query' => array(
'key' => 'start_date',
'compare' => '>',
'value' => $today,
),
'meta_key' => 'start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
$upcoming_events = new WP_Query( $args );
/* If there are future events, show the upcoming events section. */
if ( $upcoming_events->have_posts() ) : ?>
<div class="upcoming-events">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="upcoming-events-head">
<h1>Upcoming Events</h1>
</div>
</div>
</div>
<?php while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post(); ?>
<div class="card container mb-4">
<div class="card-data container-grid">
<div class="card-img">
<?php the_post_thumbnail(); ?>
</div>
<div class="card-body">
<h2 class="card-title">
<?php $event_url = get_post_meta( get_the_ID(), 'event_url', true ); ?>
<?php if($event_url) : { ?>
<a href="<?php echo $event_url; ?>" target="_blank">
<?php the_title(); ?></a>
<?php } else : { ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
<?php } endif; ?>
</h2>
<p class="card-text card-date"><i class="fas fa-calendar-day fa-lg"></i>
<?php $custom_start_date = get_field('start_date', false, false);
$custom_start_date = new DateTime($custom_start_date);
$custom_end_date = get_field('end_date', false, false);
$custom_end_date = new DateTime($custom_end_date);
?>
<?php echo $custom_start_date->format('Y-m-d'); ?> to
<?php echo $custom_end_date->format('Y-m-d'); ?>
</p>
<?php if( get_field('location') ) : ?>
<p class="card-text card-location"><i class="fas fa-map-marked-alt"></i>
<?php the_field('location'); ?>
</p>
<?php endif; ?>
</div>
</div>
<div class="card-footer card-info">
<?php if ( has_excerpt() ) : the_excerpt();
else : the_content();
endif; ?>
</div>
</div>
<?php endwhile; else : ?>
<p>
<?php __('Sorry, there are no upcoming events right now. Please check back again later. :)'); ?>
</p>
<?php endif;
wp_reset_postdata(); ?>
</div>
</div>
<div class="past-events">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="past-events-head">
<h1>Past events</h1>
</div>
</div>
</div>
<div class="past-events-content-wrapper">
<div class="past-events-content">
<ul class="past-events-list list-unstyled">
<?php
/* Filter for past events starts after heading display, as the list of past events will never be empty. */
$today = date('Ymd');
$args = array(
'post_type' => 'obf-events',
'meta_query' => array(
'key' => 'end_date',
'compare' => '<',
'value' => $today,
),
'meta_key' => 'end_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
$past_events = new WP_Query( $args );
if ( $past_events->have_posts() ) : while ( $past_events->have_posts() ) : $past_events->the_post();
?>
<li>
<?php $event_url = get_post_meta( get_the_ID(), 'event_url', true ); ?>
<?php if($event_url) : { ?>
<a href="<?php echo $event_url; ?>" target="_blank">
<?php the_title(); ?></a>
<?php } else : { ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
<?php } endif; ?>
<p class="info-past">
<?php $custom_start_date = get_field('start_date', false, false);
$custom_start_date = new DateTime($custom_start_date);
$custom_end_date = get_field('end_date', false, false);
$custom_end_date = new DateTime($custom_end_date);
?>
<?php echo $custom_start_date->format('Y-m-d'); ?> to
<?php echo $custom_end_date->format('Y-m-d');
if( get_field('location') ) : ?>
,
<?php the_field('location'); endif; ?>.</p>
</li>
<?php endwhile; else : ?>
<p>
<?php __('No past events found!'); ?>
</p>
<?php endif;
wp_reset_postdata(); ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>