-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-handbook-card.php
438 lines (328 loc) · 18.9 KB
/
page-handbook-card.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?php /* Template Name: Page handbook card */ ?>
<!doctype html>
<?php get_header(); ?>
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
$postcat = get_the_category( $post->ID );
foreach( $postcat as $cat ) {
$cat_color = get_field('category_color', $cat);
if (!empty($cat->parent)) {
$cat_color = 'style = "--cat-color:'.$cat_color.'"';
}
}
?>
<section class="cards-slider" <?php echo $cat_color; ?>>
<?php
$current_cardID = get_the_ID();
$cat_card = get_cat_ID('Card');
$cat_getting_prepared_card = get_cat_ID('Getting prepared');
$cards_handbook = get_posts(array(
'fields' => 'ids',
'post_type' => 'page',
'posts_per_page' => -1,
'child_of' => $post->post_parent,
'category__in' => $cat_card
));
$cards_getting_prepared = get_posts(array(
'fields' => 'ids',
'post_type' => 'page',
'posts_per_page' => -1,
'cat' => array($cat_getting_prepared_card)
));
$cardslist = array_merge($cards_handbook, $cards_getting_prepared);
$firstID = $cardslist[0];
$lastID = end($cardslist);
$total = count($cardslist);
$current = array_search(get_the_ID(), $cardslist);
$prevID = $cardslist[$current-1];
$nextID = $cardslist[$current+1];
if( $current == get_the_ID($post) ){
$active_class = 'class="active"';
} else {
$active_class = '';
}
if( $cardslist > 1 ) {
if( $post->post_parent ) {
$post_parent_link = get_permalink($post->post_parent);
} else {
//TODO: Change the way we're getting this post parent page when we're in a getting prepared card
$post_parent_link = get_permalink( get_page_by_title( 'The Crisis Handbook' ) );
}
?>
<nav class="cards-nav">
<a href="<?php echo $post_parent_link; ?>" title="All cards"><span>All cards</span></a>
<?php if (!empty($prevID)) {
?>
<a class="previous" href="<?php echo get_permalink($prevID); ?>" title="Previous card">←</a>
<?php } else { ?>
<a class="previous" href="<?php echo get_permalink($lastID); ?>" title="Previous card">←</a>
<?php } ?>
<?php
// the main query
$query_cardslist = new WP_Query(array(
'post__in' => $cardslist,
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
));
if ( $query_cardslist->have_posts() ) :
$i = 1;
while ( $query_cardslist->have_posts() ) : $query_cardslist->the_post();
if($current_cardID == get_the_ID()){ $active_class = 'class="active"'; } else { $active_class = ''; }
?>
<a <?php echo $active_class; ?> href="<?php echo get_permalink(); ?>" title="<?php echo get_the_title(); ?>"><?php echo $i++; ?></a>
<?php endwhile; wp_reset_postdata(); endif; ?>
<?php if ($lastID == $current_cardID) { ?>
<a class="next" href="<?php echo get_permalink($firstID); ?>" title="Next card">→</a>
<?php } else if (!empty($nextID)) { ?>
<a class="next" href="<?php echo get_permalink($nextID); ?>" title="Next card">→</a>
<?php } else { ?>
<a class="next" href="<?php echo get_permalink($firstID); ?>" title="Next card">→</a>
<?php } ?>
</nav>
<?php } ?>
<article class="card full">
<header>
<h1><?php the_title(); ?></h1>
<?php
$card_image = get_field('icon');
$card_image_url = $card_image['url'];
$card_image_alt = $card_image['alt'];
if(!empty($card_image)) :
?>
<figure class="icon">
<img src="<?php echo $card_image_url; ?>" alt="<?php echo $card_image_alt; ?>">
</figure>
<?php endif; ?>
<?php the_excerpt(); ?>
<?php
$companion_image = get_field('companion_image');
$companion_url = get_field('companion_url');
$companion_overlay = get_field('companion_overlay');
if($companion_overlay == 1) {
$companion_button = '<button class="open companion" type="button"><span>Open</span></button>';
} else {
$companion_button = '<a class="button open" href="'.$companion_url.'">Open</a>';
}
if(!empty($companion_image)) {
$companion_image_alt = $companion_image['alt'];
if(!empty($companion_image_alt)) {
$companion_image_alt = 'alt="'.$companion_image_alt.'"';
}
?>
<div class="companion-content">
<figure class="companion-image">
<img src="<?php echo esc_url($companion_image['url']); ?>" <?php echo $companion_image_alt; ?>>
</figure>
<?php print $companion_button; ?>
</div>
<aside class="slide companion" aria-hidden="true">
<div class="buttons">
<!-- <a class="button download" href="" download>Download</a> -->
<button class="close open companion" type="button">Close</button>
</div>
<figure>
<img src="<?php echo $companion_url ?>">
</figure>
</aside>
<?php } ?>
</header>
<?php
$content = get_the_content();
if(!empty($content)) {
$expandable_class = 'container-expandable';
} else {
$expandable_class = '';
}
?>
<section class="intro">
<header class="card-meta">
<?php
if( have_rows('repeater_card_meta') ):
while( have_rows('repeater_card_meta') ) : the_row();
$label = get_sub_field('card_meta_label');
$description = get_sub_field('card_meta_description');
?>
<p><strong><?php echo $label; ?>:</strong> <?php echo $description; ?></p>
<?php
endwhile;
endif;
$content_size = count_content_words($content);
if( !empty($content) && $content_size > 100 ){
?>
<button class="button-expandable" type="button"><span>Read more ↓</span></button>
<?php } ?>
</header>
<?php $content_size = count_content_words($content);
if( !empty($content) && $content_size > 100 ){
?>
<div class="container-expandable">
<button class="button-expandable" type="button"><span>Read more ↓</span></button>
<div class="content expandable">
<?php echo $content; ?>
</div>
</div>
<?php } else { ?>
<div class="content">
<?php echo $content; ?>
</div>
<?php } ?>
</section>
<?php
$card_steps = get_field('repeater_card_steps'); // TODO: ? // QUESTION: Why are there two variables for the same thing?
$card_tools = get_field('repeater_card_steps');
if ($card_steps > 0 || $card_tools > 0) :
?>
<div class="tabs">
<?php if ( have_rows('repeater_card_steps') ) : ?>
<section class="steps tab active">
<header class="tab-button">
<h2>How to</h2>
</header>
<div class="container">
<?php
while ( have_rows('repeater_card_steps') ) : the_row();
$title = get_sub_field('card_step_title');
$content = get_sub_field('card_step_content');
$tools = get_sub_field('card_step_tools');
?>
<article class="step container-expandable">
<h3 class="title-expandable"><?php print $title; ?></h3>
<?php if( !empty($content) ): ?>
<button class="button-expandable"><span>↓</span></button>
<div class="content expandable">
<?php print $content; ?>
<?php // GET RELATED TOOLS
if ( have_rows('repeater_card_step_tools') ):
?>
<aside class="related tools">
<h4>Related tools</h4>
<ul>
<?php
while ( have_rows('repeater_card_step_tools') ) : the_row();
$post_object = get_sub_field('card_step_tool');
if( $posts ):
$post = $post_object;
setup_postdata( $post );
$title = get_the_title( $post->ID );
$excerpt = get_the_excerpt( $post->ID );
$link = get_field('external_link');
if(empty($link)) {
$link = get_the_permalink($post->ID);
}
?>
<li class="related tool">
<h5><?php print $title; ?></h5>
<!-- <p><?php //print $excerpt; ?></p> -->
<a href="<?php echo esc_url($link); ?>">Go to tool →</a>
</li>
<?php wp_reset_postdata(); endif; endwhile; ?>
</ul>
</aside>
<?php endif; ?>
</div>
<?php endif; ?>
</article>
<?php endwhile; ?>
</div>
</section>
<?php endif;
if( have_rows('repeater_card_tools') ): ?>
<section class="tools tab" id="tools">
<header class="tab-button">
<h2>Tools</h2>
</header>
<div class="container">
<?php
while( have_rows('repeater_card_tools') ) : the_row();
$post_object = get_sub_field('card_tool');
if( $posts ):
$post = $post_object;
setup_postdata( $post );
$title = get_the_title( $post->ID );
$excerpt = get_the_excerpt( $post->ID );
$link = get_field('external_link');
if(empty($link)) {
$link = get_the_permalink($post->ID);
}
?>
<article class="tool" id="tool-<?php echo $slug; ?>">
<h3><?php print $title; ?></h3>
<p><?php print $excerpt; ?></p>
<a href="<?php echo esc_url($link); ?>">Learn more →</a>
</article>
<?php wp_reset_postdata(); endif; endwhile; ?>
</div>
</section>
<?php endif; ?>
</div>
<?php endif; if( have_rows('repeater_card_examples') ): ?>
<section class="examples swiper">
<header>
<h2>Examples</h2>
</header>
<ol class="examples-nav swiper-pagination"></ol>
<div class="container swiper-wrapper">
<?php
while( have_rows('repeater_card_examples') ) : the_row();
$post_object = get_sub_field('card_example');
if( $posts ):
$post = $post_object;
setup_postdata( $post );
$title = get_the_title( $post->ID );
$content = apply_filters('the_content', $post->post_content);
$image = get_post_thumbnail_id( $post->ID );
$image_url = wp_get_attachment_image_url( $image, 'medium' );
$image_alt = get_post_meta($image, '_wp_attachment_image_alt', true);
$link = get_field('external_link');
if(!empty($image)) {
if(!empty($image_alt)) {
$image_alt = 'alt="'.$image_alt.'"';
}
}
if(empty($link)) {
$link = get_the_permalink($post->ID);
}
?>
<article class="example swiper-slide">
<h3><?php echo $title; ?></h3>
<?php if(!empty($image_url)) { ?>
<figure>
<img src="<?php echo esc_url($image_url); ?>" <?php echo $image_alt; ?>>
</figure>
<?php }
echo $content;
?>
<a href="<?php echo esc_url($link); ?>" title="<?php echo $title; ?>" alt="<?php echo $title; ?>" >Learn more -></a>
</article>
<?php wp_reset_postdata(); endif; endwhile; ?>
</div>
</section>
<?php endif; ?>
<section class="participate">
<header>
<h2>Participate</h2>
<h3>Looking for some advice or would like to collaborate with Mindworks?</h3>
<p><u>Use the form below to ask us anything.</u></p>
</header>
<div class="columns">
<?php echo do_shortcode('[wpforms id="763"]'); //div.card-contact ?>
<div class="join-slack">
<img src="<?php echo get_template_directory_uri(); ?>/img/icon-slack.svg" alt="Icon slack">
<h3>Want to learn and exchange with fellow changemakers?</h3>
<p>Join the conversation on: </p>
<a class="button" href="https://join.slack.com/t/mindworkscommunity/shared_invite/zt-y8l0p9io-Qw235DSHxGvGH8ElQhJ5Zg">Slack</a>
</div>
</div>
</section>
</article>
</section>
<aside class="sidebar">
<!-- Sidenote elements -->
</aside>
<?php endwhile; endif; ?>
</main>
<?php wp_footer(); ?>
</body>
</html>