/
template-events-index.php
executable file
·175 lines (164 loc) · 5.58 KB
/
template-events-index.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
<?php
/**
* Template Name: Events Index
*/
?>
<div class="custom-landing">
<div id="event-header">
<div class="container">
<?php // faking breadcrumbs below - not using yoast function ?>
<p id="breadcrumbs"><span xmlns:v="http://rdf.data-vocabulary.org/#"><span typeof="v:Breadcrumb"><a href="<?= esc_url(home_url('/')); ?>" rel="v:url" property="v:title">Home</a> » <span rel="v:child" typeof="v:Breadcrumb"><a href="<?php echo esc_url( get_permalink(25) ); ?>" rel="v:url" property="v:title"><?php echo get_the_title(25); ?></a></span> » <strong class="breadcrumb_last"><?php the_title(); ?></strong></span></span></p>
<h1><?php the_title(); ?></h1>
</div>
</div>
<div class="container">
<div class="row event-content">
<div class="col-md-5">
<h3>All Events</h3>
<ul class="list-unstyled">
<script>
console.log('CURRENT DATE: <?php echo current_time('Ymd'); ?>');
</script>
<?php
$current_date = current_time('Ymd');
$args = array(
'numberposts' => -1,
'post_type' => 'events',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'end_date',
'meta_query' =>
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $current_date
)
);
$the_query = new WP_Query( $args ); ?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$contact_address = get_field('location');
$address = explode( "," , $contact_address['address']);
$location = get_field('location');
$originalStart = get_field('start_date');
$newStart = date("F j, Y", strtotime($originalStart));
$originalEnd = get_field('end_date');
$newEnd = date("F j, Y", strtotime($originalEnd));
?>
<li>
<a href="<?php the_permalink(); ?>" class="event-title"><?php the_title(); ?></a>
<span class="event-start"><strong>Starts:</strong> <?php echo $newStart; ?></span>
<span class="event-start"><strong>Ends:</strong> <?php echo $newEnd; ?></span>
<span class="event-address"><?php echo $address[1].','.$address[2]; ?></span>
</li>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
<div class="col-md-7">
<iframe style="border: 0;" src="https://www.google.com/calendar/embed?showTitle=0&showTz=0&showCalendars=0&showTabs=0&src=uu694da6pkqq7nvd64p9bpsr38%40group.calendar.google.com&ctz=America/New_York" width="100%" height="500" frameborder="0" scrolling="no"></iframe>
</div>
</div>
</div>
<div>
<span id="event-map">Events Map</span>
<div class="acf-map">
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'events',
'meta_key' => 'end_date',
'meta_query' =>
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $current_date
)
);
$the_query = new WP_Query( $args ); ?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$contact_address = get_field('location');
$address = explode( "," , $contact_address['address']);
$location = get_field('location');
$originalStart = get_field('start_date');
$newStart = date("F j, Y", strtotime($originalStart));
$originalEnd = get_field('end_date');
$newEnd = date("F j, Y", strtotime($originalEnd));
?>
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<span class="event-start"><strong>Starts:</strong> <?php echo $newStart; ?></span>
<br />
<span class="event-start"><strong>Ends:</strong> <?php echo $newEnd; ?></span>
<p class="address"><?php echo $location['address']; ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
(function($) {
function new_map( $el ) {
var $markers = $el.find('.marker');
var args = {
zoom : 16,
center : new google.maps.LatLng(0, 0),
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map( $el[0], args);
map.markers = [];
$markers.each(function(){
add_marker( $(this), map );
});
center_map( map );
return map;
}
function add_marker( $marker, map ) {
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
var marker = new google.maps.Marker({
position : latlng,
map : map
});
map.markers.push( marker );
if( $marker.html() )
{
var infowindow = new google.maps.InfoWindow({
content : $marker.html()
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open( map, marker );
});
}
}
function center_map( map ) {
var bounds = new google.maps.LatLngBounds();
$.each( map.markers, function( i, marker ){
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
bounds.extend( latlng );
});
if( map.markers.length == 1 )
{
map.setCenter( bounds.getCenter() );
map.setZoom( 16 );
}
else
{
map.fitBounds( bounds );
}
}
var map = null;
$(document).ready(function(){
$('.acf-map').each(function(){
map = new_map( $(this) );
});
$("#event-header").backstretch("//cdn.vmturbo.com/wp-content/uploads/2014/04/qos_04.jpg");
});
})(jQuery);
</script>