Project

General

Profile

Feature #5347 » functions.php

Alex Hills, 2016-03-21 08:09 AM

 
1
<?php
2
/**
3
 * MESTC Child Theme Functions
4
 *
5
 * This file supplements the functions defined in THEMATIC to allow for specific MESTC functionality.
6
 *
7
 * @link http://docs.thematictheme.com
8
 *
9
 * @package MESTC
10
 * @subpackage ThemeInit
11
 */
12

    
13

    
14
/**
15
 * Unleash the power of Thematic's dynamic classes, comment form and feedlinks.
16
 *
17
 * These constants were removed in Themeatic v1.0.3.1, introducing a bug that broke the MESTC site.
18
 * add_theme_support() was added to fix the bug. On 11/9/12 I (Dom) upgraded Themeatic to v1.0.3.3-beta:
19
 * https://github.com/ThematicTheme/Thematic/archive/1.0.3.3-beta.zip
20
 *
21
 * For additional information about this bug and fix please see this forum topic:
22
 * http://thematictheme.com/forums/topic/upgrading-to-v-1-0-3-1-and-body_class-in-functions-php/page/2/#post-2488
23
 */
24
// define('THEMATIC_COMPATIBLE_BODY_CLASS', true);
25
// define('THEMATIC_COMPATIBLE_POST_CLASS', true);
26
add_theme_support('thematic_legacy_body_class');
27
add_theme_support('thematic_legacy_post_class');
28

    
29
// define('THEMATIC_COMPATIBLE_COMMENT_FORM', true);
30
add_theme_support( 'thematic_legacy_comment_form' );
31

    
32
// define('THEMATIC_COMPATIBLE_FEEDLINKS', true);
33
add_theme_support( 'thematic_legacy_feedlinks' );
34

    
35

    
36
global $page;
37
global $post;
38

    
39
//Add Favicon
40

    
41
function childtheme_favicon() { 
42
	$MESTCimagedir = get_stylesheet_directory_uri();
43
	$MESTCimagedir .= '/library/images/';?>
44
    <link rel="shortcut icon" href="<?php echo $MESTCimagedir ?>favicon.ico">
45
<?php }
46

    
47
add_action('wp_head', 'childtheme_favicon');
48

    
49

    
50
	
51
// Replace Blog Title with MESTC logo
52

    
53
function childtheme_override_blogtitle(){
54
		$MESTCimagedir = get_stylesheet_directory_uri();
55
		$MESTCimagedir .= '/library/images/';
56
		if (is_page('index')){
57
		?>
58
	  	<div id="MESTC-image"><span><a href="<?php echo home_url() ?>/" title="Martin E. Segal Theatre Center" rel="home"><img
59
src="<?php echo $MESTCimagedir ?>MESTCBig.jpg" height="175px" width="225px"></a></span></div><?php		
60
		}
61
		else {
62
	    ?>
63
    	<div id="MESTC-image"><span><a href="<?php echo home_url() ?>/" title="Martin E. Segal Theatre Center" rel="home"><img
64
src="<?php echo $MESTCimagedir ?>MESTC.jpg" height="134px" width="170px"></a></span></div>  
65
    <?php 
66
	}
67
}
68

    
69
add_action('thematic_header','thematic_blogtitle',3);    
70

    
71

    
72

    
73
// Register the new menus
74
function register_my_menus() {
75
	register_nav_menus(
76
		array(
77
			'primary-menu' => __( 'Primary Menu' ),
78
			'home-menu' => __( 'Home Menu' ),
79
			'events-menu' => __( 'Events Menu' ),
80
	        'publications-menu' => __( 'Publications Menu' ),
81
		)
82
	);
83
}
84
add_action( 'init', 'register_my_menus' );
85

    
86

    
87

    
88
//Conditional Assignment of Secondary Menu Based on Category
89
function secondary_header_menu() {
90
	if (tribe_is_event()) {
91
         wp_nav_menu( array( 'theme_location' => 'events-menu',
92
				'container_id'=>'secondary-header-menu',
93
				'container_class' => 'clearfix ',
94
                'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too       
95
				) );
96
	}			
97
	elseif (is_single() OR is_archive()) {
98
		  wp_nav_menu( array( 'theme_location' => 'home-menu',
99
				'container_id'=>'secondary-header-menu',
100
				'container_class' => 'clearfix ',
101
              'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too
102
              ) );
103
	}
104
	elseif (in_category('events')) {
105
         wp_nav_menu( array( 'theme_location' => 'events-menu',
106
				'container_id'=>'secondary-header-menu',
107
				'container_class' => 'clearfix ',
108
                'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too       
109
				) );
110
	}
111
	elseif (in_category('publications' )) {
112
         wp_nav_menu( array( 'theme_location' => 'publications-menu',
113
				'container_id'=>'secondary-header-menu',
114
				'container_class' => 'clearfix ',
115
                'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too
116
                ) );
117
	}
118
	else {
119
		  wp_nav_menu( array( 'theme_location' => 'home-menu',
120
				'container_id'=>'secondary-header-menu',
121
				'container_class' => 'clearfix ',
122
                'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too
123
                ) );
124
	}	
125
}
126

    
127
add_action('thematic_header','secondary_header_menu');
128

    
129

    
130

    
131
// Assign Background image to Headers and Add Secondary Header Menu
132
function childtheme_override_access(){ 
133
	$MESTCimagedir = get_stylesheet_directory_uri();
134
	$MESTCimagedir .= '/library/images/';
135
	if (is_page('index')) { ?>
136
	<div id="access"> <?php
137
    } 	
138
    else { 
139
		if (in_category('events')) {
140
            $headerimage = 'MESTCEventHeader.jpg';
141
        }
142
        elseif (in_category('publications')) {
143
            $headerimage = 'MESTCPubHeader.jpg';
144
        }
145
        elseif (in_category('home')) {
146
            $headerimage = 'MESTCHomeHeader.jpg';
147
		}
148
		elseif (tribe_is_event() OR tribe_is_month() OR tribe_is_list_view()) {
149
            $headerimage = 'MESTCEventHeader.jpg';
150
		}
151
		elseif (is_single() OR is_archive()) {
152
            $headerimage = 'MESTCHomeHeader.jpg';
153
		}
154
        else {
155
            $headerimage = 'MESTCEventHeader.jpg';
156
        }
157
	    ?>
158
        <div id="access" style="background: url('<?php echo $MESTCimagedir.$headerimage ?>') no-repeat"> <?php
159
    }
160
	if ( ( function_exists("has_nav_menu") ) && ( has_nav_menu( apply_filters('thematic_primary_menu_id', 'primary-menu') ) ) ) {
161
    	    echo  wp_nav_menu(thematic_nav_menu_args());
162
    	} else {
163
    	    echo  thematic_add_menuclass(wp_page_menu(thematic_page_menu_args()));	
164
    	}
165
    if (!is_page('index')){
166
		secondary_header_menu();}?>
167
    </div><!-- #access -->
168

    
169
    <?php
170
    if(!is_page('index')){ ?>
171
    	<?php
172
    	$tag = get_field('tag_line', 'options');
173
    	if($tag){ ?>
174
		    <div id="header_tag">
175
		    	<div class="tag_content">
176
		    		<?php echo $tag; ?>
177
		    	</div>
178
		    </div>
179
	   	<?php }; ?>
180
	<?php }; ?>
181
    <?php 
182
}
183
add_action('thematic_header','thematic_access',9);
184

    
185

    
186

    
187
/* IMPORTANT !
188
* This function registers the same custom post type as the The Events Calendar plugin
189
* http://wordpress.org/extend/plugins/the-events-calendar/
190
* This also registers WordPress' native categories and tags while associating them with the Events Calendar Plugin
191
*/
192
add_action( 'init', 'add_calendar_taxonomy', 0 );
193

    
194
function add_calendar_taxonomy() {
195

    
196
register_post_type('tribe_events',array( // Registers Events Calendar Custom Post Type
197

    
198
'taxonomies' => array('category') // This registers the native WordPress taxonomies with The Events Calendar
199

    
200
));
201

    
202
}
203

    
204

    
205

    
206
// Randomizes background of Index page and adds caption and photo credits
207

    
208
function randomize_index_background () {
209
	if (is_page('index')){
210
		$images = get_field('splash_page_images','options');
211
		if( $images ):
212
			$n = 0;
213
			foreach( $images as $image ): 
214
				$background_images[$n] = $image['url'];
215
				$n++;
216
			endforeach;
217
		endif;
218
	
219
		if( $images ):
220
			$n = 0;
221
			foreach( $images as $image ): 
222
				$credits[$n] = $image['caption'];
223
				$n++;
224
			endforeach;
225
		endif;
226

    
227
		if( $images ):
228
			$randomnum = rand(0, count( $images ));
229
		endif;
230
	
231
    ?><div id="bgpic" style="background: url(<?php echo $background_images[$randomnum]?>) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;">
232
	</div>
233
	
234
    <div id="credits">
235
		<span class="credits"><?php echo $credits[$randomnum]?></span>
236
	</div>
237
	<?php
238
	}
239
}
240

    
241
add_action ('thematic_before', 'randomize_index_background', 1);
242
	
243
	
244
	
245

    
246

    
247
	
248
// Add Events List and Calendar Button to Events Page
249

    
250
function add_calendar_buttons() {
251
	if (is_page('events')){
252
		?><div id="tribe-events-calendar-header" class="clearfix">
253
			<span class="tribe-events-calendar-buttons"><a class="tribe-events-button-off" href="<?php echo get_site_url(); ?>/events-list/upcoming/">Event List</a>
254
			<a class="tribe-events-button-off" href="<?php echo get_site_url(); ?>/events-list/month/">Calendar</a>
255
			</span>
256
		</div><?php
257
	}
258
}
259
add_action ('thematic_abovecontent', 'add_calendar_buttons', 1);
260

    
261

    
262
// This returns the upcoming event for each category on the Events page
263

    
264
function return_upcoming_category_event($upcomingcategory){
265
	$all_events = tribe_get_events(
266
        array(
267
            'eventDisplay'=>'upcoming',
268
            'posts_per_page'=>1,
269
            'tax_query'=> array(
270
                array(
271
                    'taxonomy' => 'tribe_events_cat',
272
                    'field' => 'slug',
273
                    'terms' => $upcomingcategory
274
                )
275
            )
276
    )
277
    );
278

    
279
    foreach($all_events as $post) {
280
    setup_postdata($post);
281
    $space = false; 
282
	$output = '';
283
	$key="short-title"; 
284
	?>
285
	<hr class="next-event">
286
    <dl class="upcoming-event"> 
287
		<dt class="when-event <?php echo $class ?> "><b>Next Event:</b> <?php echo tribe_get_start_date($post->ID, false ); ?>&nbsp;-&nbsp;</dt>
288
		<dd class="what-event"><a href="<?php echo get_permalink($post->ID)?>" class="<?php echo $upcomingcategory ?>"><?php echo get_post_meta($post->ID, $key, true); ?></a></dd>
289
	</dl>
290
    <?php } //endforeach ?>
291
        <?php wp_reset_query(); 
292
}
293

    
294

    
295
// This generates the season Calendar-at-a-Glance for the Events page
296

    
297
function events_page_side_calendar () {
298
	$key="short-title";
299

    
300
	if (is_page('events') OR tribe_is_event($post->ID)){
301
		$get_posts = tribe_get_events(
302
	        array(
303
	            'eventDisplay'=>'upcoming',
304
	            'tax_query'=> array(
305
	                array(
306
	                    'taxonomy' => 'tribe_events_cat',
307
	                    'field' => 'slug',
308
	                    'terms' => 'current-season'
309
	                )
310
	            )
311
	    )
312
	    );
313
?>
314
	<div id="events-at-a-glance">
315
	<?php if (!empty($get_posts)){ ?>
316
	<h2 class="events-sidecal-subheader">Upcoming Events:</h2>
317
	<dl class="events-sidecal-event">
318
	<?php
319

    
320
	$month = date('F');
321
	$showmonth = false;
322
	$monthcount = 0;
323

    
324
	foreach($get_posts as $eventpost) { 
325
		setup_postdata($eventpost);
326
		
327
	   	if (has_term('us-theatre','tribe_events_cat',$eventpost)) {
328
			$eventcal = 'us-theatre';
329
		}
330
		elseif (has_term('international-theatre','tribe_events_cat',$eventpost))  {
331
			$eventcal = 'international-theatre';
332
		}
333
		elseif (has_term('publication-theatre','tribe_events_cat',$eventpost))  {
334
			$eventcal = 'publication-theatre';
335
		}
336
		elseif (has_term('conferences','tribe_events_cat',$eventpost)) {
337
			$eventcal = 'conferences';
338
		}
339
		elseif (has_term('screenings','tribe_events_cat',$eventpost)) {
340
			$eventcal = 'screenings';
341
		}//endif
342
		
343
		$eventmonth = tribe_get_start_date( $eventpost->ID, false, 'F' );
344
		
345
		if ($eventmonth != $month){
346
			$month = $eventmonth;
347
			$showmonth = true;
348

    
349
		} //end if
350
	
351
		if ($monthcount == 0 || $showmonth == true){
352
			$monthheader = '<h2 class="events-sidecal-month">';
353
			$monthheader .= $month;
354
			$monthheader .= '</h2>';
355
			echo $monthheader;				
356
		} // endif
357
		
358
		$showmonth = false;
359
		$monthcount = 1;
360
		$event_id = $eventpost->ID;
361
		?>
362
		
363
        <dt class="event-short-date"><?php echo tribe_get_start_date( $eventpost->ID, false, 'M j' );?></dt>
364
        <dd class="event-short-title"><div class="<?php echo $eventcal;?>"><a href="<?php echo get_permalink($eventpost->ID); ?>" id="post-<?php echo $eventpost->ID ?>"><?php echo get_post_meta($eventpost->ID, $key, true); ?></a></div>
365
		</dd>
366
<?php } //endforeach ?>
367

    
368
    </dl>
369
    <?php 
370
	}
371
		$get_oldposts = tribe_get_events(
372
	        array(
373
	            'eventDisplay'=>'past',
374
	            'tax_query'=> array(
375
	                array(
376
	                    'taxonomy' => 'tribe_events_cat',
377
	                    'field' => 'slug',
378
	                    'terms' => 'current-season'
379
	                )
380
	            )
381
	    )
382
	    );
383
	
384
		
385
	$get_oldposts = array_reverse($get_oldposts);
386
	
387
	if (!empty($get_oldposts)){
388
	?>
389

    
390
		<h2 class="events-sidecal-subheader2">Past Events:</h2>
391
		<dl class="events-sidecal-event"><?php
392
		
393
		$month = 'none';	
394
		$showmonth = false;
395
		
396
		foreach($get_oldposts as $eventpost) { 
397
			setup_postdata($eventpost); 
398
			
399
			$current_date = date('j');
400
			$event_date = tribe_get_start_date( $eventpost->ID, false, 'j' );
401

    
402
			if ($current_date!=$event_date){
403

    
404
			   	if (has_term('us-theatre','tribe_events_cat',$eventpost)) {
405
					$eventcal = 'us-theatre';
406
				}
407
				elseif (has_term('international-theatre','tribe_events_cat',$eventpost))  {
408
					$eventcal = 'international-theatre';
409
				}
410
				elseif (has_term('publication-theatre','tribe_events_cat',$eventpost))  {
411
					$eventcal = 'publication-theatre';
412
				}
413
				elseif (has_term('conferences','tribe_events_cat',$eventpost)) {
414
					$eventcal = 'conferences';
415
				}
416
				elseif (has_term('screenings','tribe_events_cat',$eventpost)) {
417
					$eventcal = 'screenings';
418
				}//endif
419
			
420
				$eventmonth = tribe_get_start_date( $eventpost->ID, false, 'F' );
421
				
422
				if ($eventmonth != $month){
423
					$month = $eventmonth;
424
					$showmonth = true;
425
				} //end if
426
		
427
				if ($showmonth == true){
428
					$monthheader = '<h2 class="events-sidecal-month">';
429
					$monthheader .= $month;
430
					$monthheader .= '</h2>';
431
					echo $monthheader;				
432
				} // endif
433
			
434
				$showmonth = false;
435
				$eventclass = 'us-theatre';
436
				
437
				?>
438
			
439
				<dt class="event-short-date"><?php echo tribe_get_start_date( $eventpost->ID, false, 'M j' );?></dt>
440
		        <dd class="event-short-title"><div class="<?php echo $eventcal;?>"><a href="<?php echo get_permalink($eventpost->ID); ?>" id="post-<?php echo $eventpost->ID ?>"><?php echo get_post_meta($eventpost->ID, $key, true); ?></a></div>
441
				</dd>
442
					<?php
443
			}
444
			
445
 		} //endforeach ?>
446

    
447
	    </dl>
448
	    
449
	<?php
450
	}
451
	?>
452
	</div>
453
	<?php wp_reset_query();
454
}
455
}
456

    
457
add_action('thematic_belowmainasides', 'events_page_side_calendar', 1);
(2-2/3)