-
Notifications
You must be signed in to change notification settings - Fork 1
/
open-jobs-page.php
207 lines (190 loc) · 8.02 KB
/
open-jobs-page.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
<?php
/*
Template name: Open jobs
*/
?>
<?php
/**
* The template for displaying the available jobs
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that other
* 'pages' on your WordPress site will use a different template.
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/
get_header();
$active_location = isset($_GET['job_location']) ? $_GET['job_location'] : false;
$active_field = isset($_GET['job_field']) ? $_GET['job_field'] : false;
$openJobsLocationQuery = $active_location ? [
'taxonomy' => 'job_location',
'field' => 'slug',
'terms' => $active_location,
] : [];
$openJobsFieldQuery = $active_field ? [
'taxonomy' => 'job_field',
'field' => 'slug',
'terms' => $active_field,
] : [];
$openJobsQueryArgs = [
'post_type' => 'open_jobs',
'posts_per_page' => -1,
];
if (!empty($openJobsLocationQuery) || !empty($openJobsFieldQuery)) {
$openJobsQueryArgs['tax_query'] = [
'relation' => 'AND',
];
}
if (!empty($openJobsLocationQuery)) {
$openJobsQueryArgs['tax_query'][] = $openJobsLocationQuery;
}
if (!empty($openJobsFieldQuery)) {
$openJobsQueryArgs['tax_query'][] = $openJobsFieldQuery;
}
$openJobsQuery = new WP_Query($openJobsQueryArgs);
$locations = get_terms([
'taxonomy' => 'job_location',
'hide_empty' => false,
]);
$fields = get_terms([
'taxonomy' => 'job_field',
'hide_empty' => false,
]);
$currentLink = get_the_permalink();
$today = date('Y-m-d');
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<header class="entry-header">
<div class="subpage-entry-title">
<div class="subpage-entry-title-header">
<h2 class="single_post_subheader"><?php the_field('page_subheader'); ?></h2>
<h1><?php the_title(); ?></h1>
<button class="sub_menu_button"></button>
</div>
</div>
</header><!-- .entry-header -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div id="subpage_content_container">
<?php get_sidebar(); ?>
<div id="subpage_content">
<h2 class="underline"><?php the_field('content_subheader'); ?></h2>
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<div><?php the_field('page_content'); ?></div>
<?php
if ($locations || $fields) { ?>
<div class="open-jobs-filter">
<?php
if ($locations) { ?>
<div class="open-jobs-filter__button-wrapper">
<?php
if (!$active_location) { ?>
<button class="open-jobs-filter__button open-jobs-filter__button--button open-jobs-filter__button--placeholder"><?php _e( 'Location', 'twentythirteen' ); ?></button>
<?php } else {
$linkParams = $_GET;
$linkParams['job_location'] = null;
?>
<a href="<?php echo modify_url_query($currentLink, $linkParams); ?>" class="open-jobs-filter__button open-jobs-filter__button--clear open-jobs-filter__button--link"><?php _e( 'Clear selection', 'twentythirteen' ); ?></a>
<?php }
foreach ($locations as $location) {
if (($location->slug === $active_location)) { ?>
<button class="open-jobs-filter__button open-jobs-filter__button--button"><?php echo $location->name; ?></button>
<?php } else {
$linkParams = $_GET;
$linkParams['job_location'] = $location->slug;
?>
<a href="<?php echo modify_url_query($currentLink, $linkParams); ?>" class="open-jobs-filter__button open-jobs-filter__button--link"><?php echo $location->name; ?></a>
<?php }
}
?>
</div>
<?php }
if ($fields) { ?>
<div class="open-jobs-filter__button-wrapper">
<?php
if (!$active_field) { ?>
<button class="open-jobs-filter__button open-jobs-filter__button--button open-jobs-filter__button--placeholder"><?php _e( 'Department', 'twentythirteen' ); ?></button>
<?php } else {
$linkParams = $_GET;
$linkParams['job_field'] = null;
?>
<a href="<?php echo modify_url_query($currentLink, $linkParams); ?>" class="open-jobs-filter__button open-jobs-filter__button--clear open-jobs-filter__button--link"><?php _e( 'Clear selection', 'twentythirteen' ); ?></a>
<?php }
foreach ($fields as $field) {
if (($field->slug === $active_field)) { ?>
<button class="open-jobs-filter__button open-jobs-filter__button--button"><?php echo $field->name; ?></button>
<?php } else {
$linkParams = $_GET;
$linkParams['job_field'] = $field->slug;
?>
<a href="<?php echo modify_url_query($currentLink, $linkParams); ?>" class="open-jobs-filter__button open-jobs-filter__button--link"><?php echo $field->name; ?></a>
<?php }
}
?>
</div>
<?php }
?>
</div>
<?php }
if ($openJobsQuery->have_posts()) { ?>
<div class="open-jobs">
<?php
while ($openJobsQuery->have_posts()) {
$openJobsQuery->the_post();
$name = get_the_title();
$applyLink = get_field('acf_open_job_apply_link');
$nhsApplyLink = get_field('acf_open_job_nhs_apply_link');
$closingDate = get_field('acf_open_job_closing_date');
$closingDateString = __( 'Closing date for applications', 'twentythirteen' );
$isPassed = false;
if ($closingDate && strtotime($closingDate) <= strtotime($today)) {
$isPassed = true;
$closingDateString .= ' <strong>'. __( 'was', 'twentythirteen' ) .'</strong> ';
} else {
$closingDateString .= ' '. __( 'is', 'twentythirteen' ) .' ';
}
$closingDateString .= date_i18n('j F Y', strtotime($closingDate));
?>
<div class="open-jobs__item<?php echo $isPassed ? ' open-jobs__item--passed' : ''; ?>">
<strong class="open-jobs__item-title"><?php echo $name; ?></strong>
<div class="open-jobs__item-links">
<a class="open-jobs__item-link open-jobs__item-link--red" href="<?php the_permalink(); ?>"><?php _e( 'Full job description', 'twentythirteen' ); ?></a>
<?php
if ($applyLink && !$isPassed) { ?>
<a class="open-jobs__item-link open-jobs__item-link--gray" href="<?php echo $applyLink; ?>" target="_blank"><?php _e( 'Apply', 'twentythirteen' ); ?></a>
<?php }
if ($nhsApplyLink && !$isPassed) { ?>
<a class="open-jobs__item-link open-jobs__item-link--lightgray" href="<?php echo $nhsApplyLink; ?>" target="_blank"><?php _e( 'Apply via NHS', 'twentythirteen' ); ?></a>
<?php }
?>
</div>
<span class="open-jobs__item-date"><?php echo $closingDateString; ?></span>
</div>
<?php }
wp_reset_postdata();
?>
</div>
<?php } else { ?>
<div class="open-jobs open-jobs--no-results">
<span><?php _e( 'No results', 'twentythirteen' ); ?></span>
</div>
<?php }
?>
</div>
<?php endwhile; ?>
<div id="subpage_sidebar">
<?php get_template_part('right-sidebar'); ?>
</div>
</div>
</article><!-- #post -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>