-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-azindex.php
212 lines (177 loc) · 6.03 KB
/
template-azindex.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
<?php
/**
* Template Name: A-Z Index
* Template Post Type: page, post
*/
?>
<?php get_header(); the_post(); ?>
<!-- Anchor navigation below hero -->
<div class="subnav container-fluid">
<div class="container">
<ul class="formsNav">
<li><a href="#!" class="alpha active">Alphabetical</a></li>
<li><a href="#!" class="cat">Category</a></li>
</ul>
</div>
</div>
<!-- A-Z Index Alphabetical List Container -->
<div class="container-fluid azcontentbox alpha white active">
<div class="container">
<div class="row nav">
<div class="left col-12">
<ul class="alphaLinks">
<?php
// Add 'ALL' list item
echo '<li><a href="#alphaAll" class="alphaAll active">ALL</a></li>';
// Add alphabetic list items
for ($i = 65; $i <= 90; $i++) {
$letter = chr($i);
echo "<li><a href=\"#alpha{$letter}\" class=\"alpha{$letter}\">{$letter}</a></li>";
}
// Add '#' list item for numbers
echo '<li><a href="#alphaNum" class="alphaNum">#</a></li>';
?>
</ul>
</div>
</div>
<div class="row content">
<?php
/**
* Create all Pods sections in A-Z index
* Fetch all documents under each letter/number
* Replaces iterative calls for sections
*
* @since 1.1.1
* @author Mike Setzer
**/
$params = array(
'limit' => 999,
);
//Fetch all forms_and_documents pods items and store in $documents array
$pods = pods('forms_and_documents', $params);
$documents = array();
while ($pods->fetch()) {
// Store document name for display, and sort first letter of document name for easy fetching later
$documentName = $pods->display('name');
$firstChar = strtolower($documentName[0]);
if ($pods->display('file_upload')) {
$fileurl = $pods->display('file_upload');
} else {
$fileurl = $pods->display('location_url');
}
//If the first character is a number, store in 'num' array
if (ctype_digit($firstChar)) {
$documents['num'][] = array(
'name' => $documentName,
'url' => $fileurl
);
//If the first character is a letter, store in letter array
} else {
$documents[$firstChar][] = array(
'name' => $documentName,
'url' => $fileurl
);
}
}
//Create a div for each letter/number and populate with documents
for ($i = 65; $i <= 90; $i++) {
$char = chr($i);
$charLower = strtolower($char);
echo '<div class="left col-12 alphafilelist alpha' . $char . ' active" id="alpha' . $char . '">';
echo '<h3 class="title">' . $char . '</h3>';
if (!empty($documents[$charLower])) {
echo '<ul class="dlList">';
foreach ($documents[$charLower] as $doc) {
echo '<li><a href="' . $doc['url'] . '" target="_blank">' . $doc['name'] . '</a></li>';
}
echo '</ul>';
}
echo '</div>';
}
// Generate div for numbers
echo '<div class="left col-12 alphafilelist alphaNum active" id="alphaNum">';
echo '<h3 class="title">' . '#' . '</h3>';
if (!empty($documents['num'])) {
echo '<ul class="dlList">';
foreach ($documents['num'] as $docNum) {
echo '<li><a href="' . $docNum['url'] . '" target="_blank">' . $docNum['name'] . '</a></li>';
}
echo '</ul>';
}
echo '</div>';
?>
</div>
</div>
</div>
<!-- A-Z Index Category Container -->
<div class="container-fluid azcontentbox cat white">
<div class="container">
<div class="row nav">
<div class="left azdropdown col-12">
<select class="custom-select fileselect" id="fileselect">
<option selected>Choose a category to filter by.</option>
<option value="benefits">Benefits</option>
<option value="classification-and-compensation">Classification and Compensation</option>
<option value="current-employees">Current Employees</option>
<option value="employee-recognition">Employee Recognition</option>
<option value="hiring-and-onboarding">Hiring and Onboarding</option>
<option value="leave-and-attendance">Leave and Attendance</option>
<option value="liaisons-and-supervisors">Liaisons and Supervisors</option>
<option value="new-employee-resources">New Employee Resources</option>
<option value="new-employees">New Employees</option>
<option value="other-forms-and-documents">Other Forms and Documents</option>
<option value="payroll">Payroll</option>
<option value="policies-and-compliance">Policies and Compliance</option>
<option value="retirement-and-retirees">Retirement and Retirees</option>
</select>
</div>
</div>
<div class="row content">
<?php
$categories = array(
'Benefits',
'Classification and Compensation',
'Current Employees',
'Employee Recognition',
'Hiring and Onboarding',
'Leave and Attendance',
'Liaisons and Supervisors',
'New Employee Resources',
'New Employees',
'Other Forms and Documents',
'Payroll',
'Policies and Compliance',
'Retirement and Retirees',
);
$params = array(
'limit' => 999,
);
$pods = pods('forms_and_documents', $params);
$documentsByCategory = array();
while ($pods->fetch()) {
$documentName = $pods->display('name');
$category = $pods->display('category');
$fileurl = $pods->display('file_upload') ? $pods->display('file_upload') : $pods->display('location_url');
$documentsByCategory[$category][] = array(
'name' => $documentName,
'url' => $fileurl,
);
}
foreach ($categories as $category) {
$slug = strtolower(trim(preg_replace('/[\s-]+/', '-', preg_replace('/[^A-Za-z0-9-]+/', '-', preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $category))))), '-'));
if (!empty($documentsByCategory[$category])) {
echo '<div class="left col-12 catName ' . $slug . '">';
echo '<h3 class="title">' . $category . '</h3>';
echo '<ul class="dlList">';
foreach ($documentsByCategory[$category] as $doc) {
echo '<li><a href="' . $doc['url'] . '" target="_blank">' . $doc['name'] . '</a></li>';
}
echo '</ul>';
echo '</div>';
}
}
?>
</div>
</div>
</div>
<?php get_footer(); ?>