-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpl-activities.php
executable file
·217 lines (189 loc) · 7.95 KB
/
tpl-activities.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
<?php
/**
* Template Name: Activities list with filters
*/
?>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php
$pageFeaturedImage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
?>
<div class="hero hero--default">
<div class="hero--alt__img" style="background-image: url(<?php echo $pageFeaturedImage[0]; ?>);"></div>
<div class="uk-container uk-container-center">
<div class="uk-grid">
<div class="uk-width-medium-6-12 uk-push-1-12 hero-header">
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="uk-container uk-container-center">
<div class="main-container main-container--activities main-container-mt-neg">
<main class="masonry-container">
<div class="pos-r">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="hero-header">
<h1 class="hero__title"><?php the_title(); ?></h1>
<?php
if(get_field('page_subtitle'))
{
echo '<p class="hero__subtitle">' . get_field('page_subtitle') . '</p>';
}
?>
</div>
<?php endwhile; ?>
<div class="filters filters-aligned"></div>
<div class="masonry">
<div class="filters-content">
<?php
$filter1 = array(
'name' =>'activity_place',
'type' =>'choice'
);
$filter2 = array(
'name' =>'activity_type',
'type' =>'choice'
);
$filter3 = array(
'name' =>'target',
'type' =>'choice'
);
// Range sliders: params are mandatory
// Indicate the label and the data type (hour or not) so it displays it in days/hours/min
$filter4 = array(
'name' =>'people_num',
'type' =>'rangeSlider',
'label' => __('Number of players', 'site'),
'data-hour' =>'false'
);
$filter5 = array(
'name' =>'hour_num',
'type' =>'rangeSlider',
'label' => __('Duration', 'site'),
'data-hour' =>'true'
);
$filter6 = array(
'name' =>'activity_follow_up',
'type' =>'bool'
);
$filter7 = array(
'name' =>'personalisation',
'type' =>'bool'
);
$filter8 = array(
'name' =>'in_movement',
'type' =>'bool'
);
$filters=array($filter1, $filter2, $filter3, $filter4, $filter5, $filter6, $filter7, $filter8);
//DISPLAY FILTERS
echo get_filters($filters);
?>
<div class="filter-search">
<form action="" method="get">
<input type="search" name="filter_search" id="filter-search__input" placeholder="<?php _e('Search', 'site');?>" value="<?php if(isset($_GET['filter_search'])) echo $_GET['filter_search'];?>">
<!-- input type="hidden" name="post_type" value="activite" -->
<?php
if(isset($_GET) && count($_GET) > 0) {
foreach ($_GET as $getKey => $getValue) {
if( $getKey != 'page' && $getKey != 'paged' && $getKey != 'filter_search' && $getValue != '' ) {
echo '<input type="hidden" name="'. $getKey .'" value="' . $getValue . '">';
}
}
}
?>
<button class="search-icon"><svg class="ug-Svg-icon ug-Svg--search"><use xlink:href="#ug-Svg--search" /></svg></button>
</form>
</div>
<?php if(isset($_GET) && count($_GET) > 0) { ?>
<div class="filter filter-reset">
<a href="<?php echo get_permalink();?>?" class="uk-button">Reset <svg class="ug-Svg-icon ug-Svg--closemenu"><use xlink:href="#ug-Svg--closemenu" /></svg></a>
</div>
<?php } ?>
</div>
<?php
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
// doing the meta_query based on $_GETs
$args=array();
$args['post_type']= 'activite';
$meta_query = array();
if(isset($_GET) && count($_GET) > 0) {
foreach ($_GET as $key => $value) {
if( $key != 'page' && $key != 'paged' && $value != 'all' && $key != 'filter_search' && $key != 'post_type' && $value != '' ) {
$lastCharsKey = substr($key, -4);
switch($lastCharsKey) {
// RANGES: if either min value or max value of an activity is between the min and max selection, we display it :)
// We detect the range stuff with their end ('_min' and '_max'). Not very clean but that's the only way I found
case '_min':
$firstCharsKey = substr($key, 0, -4);
$mq1 = array(
'key' => $key,
'value' => array($value-1, $_GET[$firstCharsKey.'_max']+1), 'compare' => 'BETWEEN','type' => 'NUMERIC'
);
$mq2 = array(
'key' => $firstCharsKey.'_max',
'value' => array($value-1, $_GET[$firstCharsKey.'_max']+1),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
);
$mq = array(
'relation' => 'OR',
$mq1,
$mq2
);
break;
case '_max':
$mq=null;
break;
// other values (select choices)
default:
$mq = array(
'key' => $key,
'value' => $value,
'compare' => 'LIKE'
);
}
if($mq != null)
array_push($meta_query, $mq);
}
if($key == 'filter_search' ) {
//echo $key . ' - ' . $value;
if($value != '')
$args['filter_search']=$value;
}
}
}
if(count($meta_query) > 0) {
$args['meta_query'] = $meta_query;
}
$args['posts_per_page'] = 6;
$args['paged'] = $paged;
add_filter( 'posts_where', 'wp_posts_where', 10, 2 );
$query = new WP_Query( $args );
remove_filter( 'posts_where', 'wp_posts_where', 10, 2 );
?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php masonry_post_no_uk(); ?>
<?php endwhile; ?>
<?php else: ?>
<h2 class="no-result"><?php _e('No result. Try other filters or click on the "reset" button', 'site');?>.</h2>
<?php endif; ?>
<?php wp_reset_query();?>
<?php wp_reset_postdata(); ?>
<?php
// Custom navigation because wp-pagenavi is buggy
echo navi_custom( $query );
?>
</div>
<div class="infinite-pagenavi-container"></div>
</div>
</main>
</div>
</div>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/footer','parts/shared/html-footer' ) ); ?>