-
Notifications
You must be signed in to change notification settings - Fork 6
/
content-interactive-map.php
64 lines (58 loc) · 1.58 KB
/
content-interactive-map.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
<?php
$maps_query = new WP_Query(array(
'post_type' => 'map',
'posts_per_page' => -1
));
$maps_data = array(
'groupID' => 'interactive_map',
'maps' => array(),
'disableHash' => true
);
if($maps_query->have_posts()) {
while($maps_query->have_posts()) {
$maps_query->the_post();
$maps_data['maps'][$post->ID] = jeo_get_map_data($post->ID);
wp_reset_postdata();
}
}
$categorized_maps = array();
foreach($maps_data['maps'] as $map) {
foreach($map['categories'] as $category) {
if(!$categorized_maps[$category->term_id])
$categorized_maps[$category->term_id] = array('term' => $category, 'maps' => array());
$categorized_maps[$category->term_id]['maps'][] = $map;
}
}
?>
<div class="interactive-map-container">
<div id="interactive-map_<?php echo $maps_data['groupID']; ?>" class="interactive-map">
<div class="map-nav-container">
<ul class="map-nav">
<?php
foreach($categorized_maps as $category) {
?>
<li>
<?php echo $category['term']->name; ?>
<ul>
<?php foreach($category['maps'] as $map) {
$post = get_post($map['postID']);
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>" data-map="<?php the_ID(); ?>"><?php the_title(); ?></a></li>
<?php
wp_reset_postdata();
} ?>
</ul>
</li>
<?php } ?>
</ul>
</div>
<div class="map-container">
<div id="interactive-map_<?php echo $maps_data['postID']; ?>_map" class="map">
</div>
</div>
</div>
</div>
<script type="text/javascript">
var group = interactiveMap(<?php echo json_encode($maps_data); ?>);
</script>