-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
310 lines (236 loc) · 8.06 KB
/
functions.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
<?php
/**
* Enqueue scripts and styles.
*/
function mendocino_scripts() {
wp_enqueue_style( 'jquery-ui.css', 'https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css', array(),'20210821', true );
wp_enqueue_script('mendo-js', get_theme_file_uri('/js/mendo.js'), array('jquery'));
wp_enqueue_script('mendo-map', get_theme_file_uri('/js/mendo-map.js'), array());
wp_enqueue_script('home-left', get_theme_file_uri('/js/home-left.js?v2'), array());
}
add_action( 'wp_enqueue_scripts', 'mendocino_scripts' );
add_action('mendo_route_alert', 'make_route_alert');
register_nav_menus( array(
'agency-information' => 'Agency Information Links',
) );
function make_route_alert($routeNumber){
global $post;
if (is_page()) {
$routes = explode('-', $routeNumber);
$call = "cat=4&showposts=5&tag=";
$multi = false;
foreach ($routes as $routeNum) {
if($multi) { $call .= ',';}
$call.= 'route-'.$routeNum.'-alert';
$multi = true;
}
//echo $call;
$posts = get_posts ($call); ?>
<?php if ($posts) {
?>
<div id="service-alert-box" class="route-box route-alert-box-<?php echo $routeNum; ?>">
<div id="service-alert-inner-box">
<?php // conditional if is double route
if ($routeNumber == "7-9") {
?> <h2>Service Alerts for Routes 7 and 9</h2>
<?php } elseif($routeNumber == "1-20") { ?>
<h2>Service Alerts for Routes 1 and 20</h2>
<?php } elseif($routeNumber == "5-60") { ?>
<h2>Service Alerts for Routes 5 and 60</h2>
<?php } else {?>
<h2>Service Alerts for Route <?php echo $routeNumber; ?></h2> <?php } ?>
<ul>
<?php
foreach ($posts as $post):
setup_postdata($post); ?>
<a href="<?php the_permalink(); ?> ">
<li>
<?php the_date(); ?> --
<?php the_title(); ?></a>
</li>
<?php endforeach;
?>
</ul>
</div> <!-- end #service alert-inner-box -->
</div> <!-- end #service alert-box -->
<?php
}
}
}
add_action('route_select', 'routeSelect');
function routeSelect() {
$q = array(
'post_type' => 'route',
'posts_per_page' => -1,
'meta_key' => 'route_sort_order',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$rtes = new WP_Query($q);
if ($rtes->have_posts()) {
echo '<div id="route-dropdown">';
echo '<select id="route-select" class="route-drop-down">';
echo '<option selected="selected">';
printf('Select a Route');
echo '</option>';
while ($rtes->have_posts()) {
$rtes->the_post();
$name = get_post_meta(get_the_ID(), 'route_long_name', true);
$sname = get_post_meta(get_the_ID(), 'route_short_name', true);
echo '<option value="';
echo $sname;
echo '">';
printf('Rt. ');
printf($sname);
printf(' ');
printf($name);
echo '</option>';
}
echo '</select>';
echo '</div>';
wp_reset_postdata();
}
}
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {
/* Register the 'primary' sidebar. */
register_sidebar(
array(
'id' => 'primary',
'name' => __( 'Primary' ),
'description' => __( 'A short description of the sidebar.' )
)
);
/* Repeat register_sidebar() code for additional sidebars. */
}
?>
<?php
$labels = array(
'name' => _x( 'News', 'post type general name' ),
'singular_name' => _x( 'News Post', 'post type singular name' ),
'menu_name' => _x( 'News', 'admin menu'),
'name_admin_bar' => _x( 'News Post', 'add new on admin bar'),
'add_new' => _x( 'Add New', 'News Post'),
'add_new_item' => __( 'Add New Post'),
'new_item' => __( 'New Post'),
'edit_item' => __( 'Edit News Post'),
'view_item' => __( 'View News Post'),
'all_items' => __( 'All News'),
'search_items' => __( 'Search News'),
'parent_item_colon' => __( 'Parent News Post:'),
'not_found' => __( 'No news found.'),
'not_found_in_trash' => __( 'No news items found in Trash.')
);
$args = array(
'menu_icon' => 'dashicons-megaphone',
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'news' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'revisions', 'editor'),
);
register_post_type( 'news', $args );
function mendo_custom_timetables() {
$route_id = get_post_meta(get_the_ID(), 'route_id', true);
$date = new DateTime();
$today = intval($date->format('Ymd'));
// Set a date 14 days in the future from today
$date->add(new DateInterval('P14D'));
$soon = intval($date->format('Ymd'));
$timetable_args = array(
'post_type' => 'timetable',
'posts_per_page' => -1,
'meta_key' => 'direction_label',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'route_id',
'value' => $route_id,
),
array(
'key' => 'start_date',
'value' => $today,
'compare' => '<=',
'type' => 'NUMERIC',
)
)
);
$timetables = new WP_Query( $timetable_args );
if ( $timetables->have_posts() ) {
$weekdayTt = get_field('weekday_timetable_label');
$weekendTt = get_field('weekend_timetable_label'); ?>
<div id="route-schedule-box-title-text" class="route-title-box-text">
Schedule
</div> <!-- #route-schedule-box-title-text -->
<div id="route-schedule-popup-info-text">
(Click to pop-up a schedule for each route)
</div> <!-- end #route-schedule-popup-info-text -->
<br style="clear: both;" />
</div>
<div id="route-days-of-week">
<?php the_field('weekday_timetable_label'); ?>
</div><!-- end #days-of-week -->
<div id="schedule-buttons">
<?php
while ( $timetables->have_posts() ) {
$timetables->the_post();
// Get timetable metadata
$permalink = get_permalink($post_id);
$dir = get_post_meta( get_the_ID(), 'direction_label', true);
$days = get_post_meta( get_the_ID(), 'days_of_week', true);
if ($days == 'Weekday' || $days == 'Mon-Sat' || $days == 'Mon-Fri') {
printf('<a href="%s"" class="timetable-link">', $permalink);
echo '<div id="schedule-northbound-65" class="route-popup-button route-button-left route-button-first route-button-odd route-button-short">';
echo '<div class="popup-button-title">';
echo $dir;
echo '</div>';
echo '</div>';
printf ('</a>');
}
}
echo '<br style="clear: both;" />';
echo '</div>';
wp_reset_postdata();
?>
<?php if ($days == 'Weekend' || $days == 'Saturday' || $days == 'Sunday') : ?>
<div id="route-days-of-week" class="route-weekend">
<?php the_field('weekend_timetable_label'); ?>
</div> <!-- end #days-of-week -->
<?php endif; ?>
<div id="schedule-buttons">
<?php while ( $timetables->have_posts() ) {
$timetables->the_post();
// Get timetable metadata
$permalink = get_permalink($post_id);
$dir = get_post_meta( get_the_ID(), 'direction_label', true);
$days = get_post_meta( get_the_ID(), 'days_of_week', true);
if ($days == 'Weekend' || $days == 'Saturday' || $days == 'Sunday') {
printf('<a href="%s"" class="timetable-link">', $permalink);
echo '<div id="schedule-northbound-65" class="route-popup-button route-button-left route-button-first route-button-odd route-button-short">';
echo '<div class="popup-button-title">';
echo $dir;
echo '</div>';
echo '</div>';
printf ('</a>');
}
}
echo '<br style="clear: both;" />';
echo '</div>';
wp_reset_postdata();
echo ' <div id="fare-table-link">';
echo '<a href="/fares/">See fare table for this route</a> >>';
echo ' </div>';
}
}
require get_template_directory() . '/inc/board-meetings-post.php';
?>