wp/wp-includes/template.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Template loading functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Retrieve path to a template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * Used to quickly retrieve the path of a template without including the file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * extension. It will also check the parent theme, if the file exists, with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * the use of {@link locate_template()}. Allows for more generic template location
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * without the use of the other get_*_template() functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @param string $type Filename without extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @param array $templates An optional list of template candidates
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @return string Full path to template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
function get_query_template( $type, $templates = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	if ( empty( $templates ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		$templates = array("{$type}.php");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	$template = locate_template( $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * Filter the path of the queried template by type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	 * The dynamic portion of the hook name, `$type`, refers to the filename
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	 * -- minus the extension -- of the file to load. This hook also applies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 * to various types of files loaded as part of the Template Hierarchy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	 * @param string $template Path to the template. See {@see locate_template()}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	return apply_filters( "{$type}_template", $template );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 * Retrieve path of index template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
 * The template path is filterable via the 'index_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
 * @return string Full path to index template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
function get_index_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	return get_query_template('index');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * Retrieve path of 404 template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
 * The template path is filterable via the '404_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
 * @return string Full path to 404 template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
function get_404_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	return get_query_template('404');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * Retrieve path of archive template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
 * The template path is filterable via the 'archive_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
 * @return string Full path to archive template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
function get_archive_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	$post_types = array_filter( (array) get_query_var( 'post_type' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	if ( count( $post_types ) == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		$post_type = reset( $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		$templates[] = "archive-{$post_type}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	$templates[] = 'archive.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	return get_query_template( 'archive', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * Retrieve path of post type archive template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
 * The template path is filterable via the 'archive_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
 * @see get_archive_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
 * @return string Full path to archive template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
function get_post_type_archive_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	$obj = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	if ( ! $obj->has_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	return get_archive_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
 * Retrieve path of author template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
 * The template path is filterable via the 'author_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
 * @return string Full path to author template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
function get_author_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
	$author = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
	if ( $author instanceof WP_User ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		$templates[] = "author-{$author->user_nicename}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		$templates[] = "author-{$author->ID}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	$templates[] = 'author.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	return get_query_template( 'author', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 * Retrieve path of category template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
 * Works by first retrieving the current slug, for example 'category-default.php', and then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
 * trying category ID, for example 'category-1.php', and will finally fall back to category.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 * template, if those files don't exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
 * The template path is filterable via the 'category_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
 * @return string Full path to category template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
function get_category_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	$category = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	if ( ! empty( $category->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		$templates[] = "category-{$category->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		$templates[] = "category-{$category->term_id}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	$templates[] = 'category.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	return get_query_template( 'category', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * Retrieve path of tag template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
 * Works by first retrieving the current tag name, for example 'tag-wordpress.php', and then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * trying tag ID, for example 'tag-1.php', and will finally fall back to tag.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 * template, if those files don't exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
 * The template path is filterable via the 'tag_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
 * @return string Full path to tag template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
function get_tag_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	$tag = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	if ( ! empty( $tag->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		$templates[] = "tag-{$tag->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		$templates[] = "tag-{$tag->term_id}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
	$templates[] = 'tag.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	return get_query_template( 'tag', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 * Retrieve path of taxonomy template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 * Retrieves the taxonomy and term, if term is available. The template is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * the taxonomy string followed by a dash and then followed by the term.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * The taxonomy and term template is checked and used first, if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 * template is used. If none of the files exist, then it will fall back on to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
 * The template path is filterable via the 'taxonomy_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
 * @return string Full path to taxonomy template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
function get_taxonomy_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
	$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	if ( ! empty( $term->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		$taxonomy = $term->taxonomy;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		$templates[] = "taxonomy-$taxonomy.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	$templates[] = 'taxonomy.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	return get_query_template( 'taxonomy', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * Retrieve path of date template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
 * The template path is filterable via the 'date_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
 * @return string Full path to date template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
function get_date_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	return get_query_template('date');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * Retrieve path of home template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 * This is the template used for the page containing the blog posts.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
 * Attempts to locate 'home.php' first before falling back to 'index.php'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
 * The template path is filterable via the 'home_template' hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
 * @return string Full path to home template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
function get_home_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	$templates = array( 'home.php', 'index.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	return get_query_template( 'home', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 * Retrieve path of front-page template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
 * Looks for 'front-page.php'. The template path is filterable via the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
 * 'front_page_template' hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
 * @return string Full path to front page template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
function get_front_page_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	$templates = array('front-page.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	return get_query_template( 'front_page', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 * Retrieve path of page template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * Will first look for the specifically assigned page template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * Then will search for 'page-{slug}.php', followed by 'page-{id}.php',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * and finally 'page.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
 * The template path is filterable via the 'page_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
 * @return string Full path to page template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
function get_page_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	$id = get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	$template = get_page_template_slug();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	$pagename = get_query_var('pagename');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	if ( ! $pagename && $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		$post = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		if ( $post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
			$pagename = $post->post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	if ( $template && 0 === validate_file( $template ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		$templates[] = $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	if ( $pagename )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		$templates[] = "page-$pagename.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	if ( $id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		$templates[] = "page-$id.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	$templates[] = 'page.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	return get_query_template( 'page', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
 * Retrieve path of paged template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
 * The template path is filterable via the 'paged_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
 * @return string Full path to paged template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
function get_paged_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	return get_query_template('paged');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 * Retrieve path of search template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
 * The template path is filterable via the 'search_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
 * @return string Full path to search template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
function get_search_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
	return get_query_template('search');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 * Retrieve path of single template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
 * The template path is filterable via the 'single_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
 * @return string Full path to single template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
function get_single_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
	$object = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	if ( ! empty( $object->post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		$templates[] = "single-{$object->post_type}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	$templates[] = "single.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	return get_query_template( 'single', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * Retrieve path of attachment template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 * The attachment path first checks if the first part of the mime type exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 * The second check is for the second part of the mime type. The last check is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 * for both types separated by an underscore. If neither are found then the file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 * 'attachment.php' is checked and returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 * finally 'text_plain.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
 * The template path is filterable via the 'attachment_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
 * @return string Full path to attachment template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
function get_attachment_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	global $posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		$type = explode( '/', $posts[0]->post_mime_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		if ( ! empty( $type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
			if ( $template = get_query_template( $type[0] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
				return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			elseif ( ! empty( $type[1] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
				if ( $template = get_query_template( $type[1] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
					return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
				elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
					return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	return get_query_template( 'attachment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 * Retrieve path of comment popup template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 * Checks for comment popup template in current template, if it exists or in the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 * parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
 * The template path is filterable via the 'comments_popup_template' hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
 * @see get_query_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
 * @return string Full path to comments popup template file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
function get_comments_popup_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	$template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	// Backward compat code will be removed in a future release
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	if ('' == $template)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		$template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
 * Retrieve the name of the highest priority template file that exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 * inherit from a parent theme can just overload one file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
 * @param string|array $template_names Template file(s) to search for, in order.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
 * @param bool $load If true the template file will be loaded if it is found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
 * @return string The template filename if one is located.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
function locate_template($template_names, $load = false, $require_once = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	$located = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	foreach ( (array) $template_names as $template_name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		if ( !$template_name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			$located = STYLESHEETPATH . '/' . $template_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		} elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			$located = TEMPLATEPATH . '/' . $template_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	if ( $load && '' != $located )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
		load_template( $located, $require_once );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	return $located;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
 * Require the template file with WordPress environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
 * The globals are set up for the template file to ensure that the WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
 * environment is available from within the function. The query variables are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
 * also available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
 * @param string $_template_file Path to template file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
 * @param bool $require_once Whether to require_once or require. Default true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
function load_template( $_template_file, $require_once = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	if ( is_array( $wp_query->query_vars ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		extract( $wp_query->query_vars, EXTR_SKIP );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	if ( $require_once )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		require_once( $_template_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		require( $_template_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505