wp/wp-includes/template.php
author ymh <ymh.work@gmail.com>
Thu, 07 Nov 2013 00:08:07 +0000
changeset 1 f6eb5a861d2f
parent 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
remove unnessary files. Make timthumb work
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * @return string Full path to file.
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
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 * The dynamic portion of the hook name, $type, refers to the filename
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
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * @since 1.5.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * @param string $template Path to the template. @see locate_template()
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
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
function get_index_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	return get_query_template('index');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * Retrieve path of 404 template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
function get_404_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	return get_query_template('404');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 * Retrieve path of archive template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
function get_archive_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	$post_types = array_filter( (array) get_query_var( 'post_type' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	if ( count( $post_types ) == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		$post_type = reset( $post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		$templates[] = "archive-{$post_type}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	$templates[] = 'archive.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	return get_query_template( 'archive', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
 * Retrieve path of post type archive template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
function get_post_type_archive_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	$post_type = get_query_var( 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	if ( is_array( $post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		$post_type = reset( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	$obj = get_post_type_object( $post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	if ( ! $obj->has_archive )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	return get_archive_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 * Retrieve path of author template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
function get_author_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	$author = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	if ( is_a( $author, 'WP_User' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$templates[] = "author-{$author->user_nicename}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$templates[] = "author-{$author->ID}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	$templates[] = 'author.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	return get_query_template( 'author', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 * Retrieve path of category template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
 * 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
   131
 * 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
   132
 * template, if those files don't exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 * @uses apply_filters() Calls 'category_template' on file path of category template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
function get_category_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	$category = get_queried_object();
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 = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	if ( ! empty( $category->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		$templates[] = "category-{$category->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		$templates[] = "category-{$category->term_id}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	$templates[] = 'category.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	return get_query_template( 'category', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 * Retrieve path of tag template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * 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
   157
 * 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
   158
 * template, if those files don't exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 * @uses apply_filters() Calls 'tag_template' on file path of tag template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
function get_tag_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	$tag = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	if ( ! empty( $tag->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		$templates[] = "tag-{$tag->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		$templates[] = "tag-{$tag->term_id}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	$templates[] = 'tag.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	return get_query_template( 'tag', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * Retrieve path of taxonomy template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 * Retrieves the taxonomy and term, if term is available. The template is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 * the taxonomy string followed by a dash and then followed by the term.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 * The taxonomy and term template is checked and used first, if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * 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
   189
 * index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
function get_taxonomy_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	$term = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	if ( ! empty( $term->slug ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
		$taxonomy = $term->taxonomy;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		$templates[] = "taxonomy-$taxonomy.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
	$templates[] = 'taxonomy.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
	return get_query_template( 'taxonomy', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * Retrieve path of date template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
function get_date_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	return get_query_template('date');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 * Retrieve path of home template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 * This is the template used for the page containing the blog posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 * Attempts to locate 'home.php' first before falling back to 'index.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * @uses apply_filters() Calls 'home_template' on file path of home template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
function get_home_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	$templates = array( 'home.php', 'index.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( 'home', $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 front-page template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 * Looks for 'front-page.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 * @uses apply_filters() Calls 'front_page_template' on file path of template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
function get_front_page_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	$templates = array('front-page.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	return get_query_template( 'front_page', $templates );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * Retrieve path of page template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * Will first look for the specifically assigned page template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 * Then will search for 'page-{slug}.php', followed by 'page-{id}.php',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 * and finally 'page.php'.
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
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
function get_page_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	$id = get_queried_object_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	$template = get_page_template_slug();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	$pagename = get_query_var('pagename');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	if ( ! $pagename && $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		// 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
   274
		$post = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		if ( $post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			$pagename = $post->post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	if ( $template && 0 === validate_file( $template ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		$templates[] = $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	if ( $pagename )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		$templates[] = "page-$pagename.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	if ( $id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		$templates[] = "page-$id.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	$templates[] = 'page.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	return get_query_template( 'page', $templates );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 * Retrieve path of paged template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
function get_paged_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	return get_query_template('paged');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 * Retrieve path of search template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
function get_search_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	return get_query_template('search');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 * Retrieve path of single template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
function get_single_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	$object = get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	$templates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	if ( ! empty( $object->post_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		$templates[] = "single-{$object->post_type}.php";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	$templates[] = "single.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( 'single', $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 attachment template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
 * 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
   336
 * 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
   337
 * 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
   338
 * 'attachment.php' is checked and returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * 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
   341
 * finally 'text_plain.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
function get_attachment_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	global $posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		$type = explode( '/', $posts[0]->post_mime_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		if ( ! empty( $type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			if ( $template = get_query_template( $type[0] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
				return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			elseif ( ! empty( $type[1] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
				if ( $template = get_query_template( $type[1] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
					return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
				elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
					return $template;
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
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
	return get_query_template( 'attachment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
 * Retrieve path of comment popup template in current or parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * 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
   372
 * parent template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
 * @uses apply_filters() Calls 'comments_popup_template' filter on path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
function get_comments_popup_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	$template = get_query_template( 'comments_popup', array( 'comments-popup.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
	// Backward compat code will be removed in a future release
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
	if ('' == $template)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		$template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	return $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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 * Retrieve the name of the highest priority template file that exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 * inherit from a parent theme can just overload one file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 * @param string|array $template_names Template file(s) to search for, in order.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 * @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
   399
 * @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
   400
 * @return string The template filename if one is located.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
function locate_template($template_names, $load = false, $require_once = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	$located = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	foreach ( (array) $template_names as $template_name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
		if ( !$template_name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			$located = STYLESHEETPATH . '/' . $template_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		} else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
			$located = TEMPLATEPATH . '/' . $template_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	if ( $load && '' != $located )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		load_template( $located, $require_once );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	return $located;
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 * Require the template file with WordPress environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 * 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
   426
 * environment is available from within the function. The query variables are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 * also available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 * @param string $_template_file Path to template file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 * @param bool $require_once Whether to require_once or require. Default true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
function load_template( $_template_file, $require_once = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	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
   436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	if ( is_array( $wp_query->query_vars ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		extract( $wp_query->query_vars, EXTR_SKIP );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	if ( $require_once )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
		require_once( $_template_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
		require( $_template_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445