View difference between Paste ID: aQJDpD0L and 4A4GJxcE
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
	function cp_template_redirect() {
4
		global $post;
5
6
		// organization single
7-
		if (is_single() && $post->post_type == 'organizations') 
7+
		if (is_single() && $post->post_type == 'organizations') {
8-
		{
8+
			$tmpl_file_name = 'single-organizations.php';
9-
			
9+
			if ( $overridden_template = locate_template( 'cp-default/'.$tmpl_file_name ) ) {
10-
			$base = 'casepress/cp-templates/default';
10+
				// locate_template() returns path to file
11-
			$includes = implode( '/', array( WP_PLUGIN_DIR, $base ) );
11+
				// if either the child theme or the parent theme have overridden the template
12-
			include_once $includes.'/hooks.php';
12+
				load_template( $overridden_template );
13-
			load_template( $includes.'/template-organization.php', true );
13+
			} else {
14
				// If neither the child nor parent theme have overridden the template,
15
				// we load the template from the 'templates' sub-directory of the directory this file is in
16
				$base = 'casepress/cp-templates/cp-default';
17
				$includes = implode( '/', array( WP_PLUGIN_DIR, $base ) );
18-
		if (is_single()) 
18+
19-
			if ($post->post_type == 'cases')
19+
				load_template( $includes.'/'.$tmpl_file_name, true );
20-
			{
20+
21-
				$base = 'casepress/cp-templates/default';
21+
22
		}
23
		
24-
				load_template( $includes.'/single-cases.php', true );
24+
25-
				die;
25+
		if (is_single() && $post->post_type == 'cases'){
26
			$tmpl_file_name = 'single-cases.php';
27
			if ( $overridden_template = locate_template( 'cp-default/'.$tmpl_file_name ) ) {
28
				// locate_template() returns path to file
29-
		if ($post->post_type == 'page')
29+
				// if either the child theme or the parent theme have overridden the template
30-
			if ($post->ID == get_option('page_for_cases_list'))
30+
				load_template( $overridden_template );
31-
			{
31+
			} else {
32-
				
32+
				// If neither the child nor parent theme have overridden the template,
33-
				$base = 'casepress/cp-templates/default';
33+
				// we load the template from the 'templates' sub-directory of the directory this file is in
34
				$base = 'casepress/cp-templates/cp-default';
35
				$includes = implode( '/', array( WP_PLUGIN_DIR, $base ) );
36-
				load_template( $includes.'/template-cases.php', true );
36+
37-
				die;
37+
				load_template( $includes.'/'.$tmpl_file_name, true );
38
			}
39
			die;
40
		}
41
42
		// cases table
43
		if ($post->post_type == 'page' && $post->ID == get_option('page_for_cases_list')){
44
			$tmpl_file_name = 'template-cases.php';
45
			if ( $overridden_template = locate_template( 'cp-default/'.$tmpl_file_name ) ) {
46
				// locate_template() returns path to file
47
				// if either the child theme or the parent theme have overridden the template
48
				load_template( $overridden_template );
49
			} else {
50
				// If neither the child nor parent theme have overridden the template,
51
				// we load the template from the 'templates' sub-directory of the directory this file is in
52
				$base = 'casepress/cp-templates/cp-default';
53
				$includes = implode( '/', array( WP_PLUGIN_DIR, $base ) );
54
				include_once $includes.'/hooks.php';
55
				load_template( $includes.'/'.$tmpl_file_name, true );
56
			}
57
			die;
58
		}
59
	}
60
	add_action('template_redirect', 'cp_template_redirect', 10);
61
?>