author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Template loading functions. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Retrieve path to a template |
|
11 |
* |
|
12 |
* Used to quickly retrieve the path of a template without including the file |
|
13 |
* extension. It will also check the parent theme, if the file exists, with |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* the use of locate_template(). Allows for more generic template location |
0 | 15 |
* without the use of the other get_*_template() functions. |
16 |
* |
|
17 |
* @since 1.5.0 |
|
18 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @param string $type Filename without extension. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @param array $templates An optional list of template candidates |
5 | 21 |
* @return string Full path to template file. |
0 | 22 |
*/ |
23 |
function get_query_template( $type, $templates = array() ) { |
|
24 |
$type = preg_replace( '|[^a-z0-9-]+|', '', $type ); |
|
25 |
||
26 |
if ( empty( $templates ) ) |
|
27 |
$templates = array("{$type}.php"); |
|
28 |
||
29 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* Filters the list of template filenames that are searched for when retrieving a template to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* The last element in the array should always be the fallback template for this query type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* @since 4.7.0 |
0 | 38 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @param array $templates A list of template candidates, in descending order of priority. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
$templates = apply_filters( "{$type}_template_hierarchy", $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
$template = locate_template( $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* Filters the path of the queried template by type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* The dynamic portion of the hook name, `$type`, refers to the filename -- minus the file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* extension and any non-alphanumeric characters delimiting words -- of the file to load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* This hook also applies to various types of files loaded as part of the Template Hierarchy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
* Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'. |
0 | 54 |
* |
5 | 55 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* @since 4.8.0 The `$type` and `$templates` parameters were added. |
0 | 57 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* @param string $template Path to the template. See locate_template(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @param string $type Filename without extension. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* @param array $templates A list of template candidates, in descending order of priority. |
0 | 61 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
return apply_filters( "{$type}_template", $template, $type, $templates ); |
0 | 63 |
} |
64 |
||
65 |
/** |
|
66 |
* Retrieve path of index template in current or parent template. |
|
67 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'index'. |
5 | 70 |
* |
0 | 71 |
* @since 3.0.0 |
72 |
* |
|
5 | 73 |
* @see get_query_template() |
74 |
* |
|
75 |
* @return string Full path to index template file. |
|
0 | 76 |
*/ |
77 |
function get_index_template() { |
|
78 |
return get_query_template('index'); |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Retrieve path of 404 template in current or parent template. |
|
83 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* and {@see '$type_template'} dynamic hooks, where `$type` is '404'. |
5 | 86 |
* |
0 | 87 |
* @since 1.5.0 |
88 |
* |
|
5 | 89 |
* @see get_query_template() |
90 |
* |
|
91 |
* @return string Full path to 404 template file. |
|
0 | 92 |
*/ |
93 |
function get_404_template() { |
|
94 |
return get_query_template('404'); |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Retrieve path of archive template in current or parent template. |
|
99 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'archive'. |
5 | 102 |
* |
0 | 103 |
* @since 1.5.0 |
104 |
* |
|
5 | 105 |
* @see get_query_template() |
106 |
* |
|
107 |
* @return string Full path to archive template file. |
|
0 | 108 |
*/ |
109 |
function get_archive_template() { |
|
110 |
$post_types = array_filter( (array) get_query_var( 'post_type' ) ); |
|
111 |
||
112 |
$templates = array(); |
|
113 |
||
114 |
if ( count( $post_types ) == 1 ) { |
|
115 |
$post_type = reset( $post_types ); |
|
116 |
$templates[] = "archive-{$post_type}.php"; |
|
117 |
} |
|
118 |
$templates[] = 'archive.php'; |
|
119 |
||
120 |
return get_query_template( 'archive', $templates ); |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* Retrieve path of post type archive template in current or parent template. |
|
125 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'archive'. |
5 | 128 |
* |
0 | 129 |
* @since 3.7.0 |
130 |
* |
|
5 | 131 |
* @see get_archive_template() |
132 |
* |
|
133 |
* @return string Full path to archive template file. |
|
0 | 134 |
*/ |
135 |
function get_post_type_archive_template() { |
|
136 |
$post_type = get_query_var( 'post_type' ); |
|
137 |
if ( is_array( $post_type ) ) |
|
138 |
$post_type = reset( $post_type ); |
|
139 |
||
140 |
$obj = get_post_type_object( $post_type ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) { |
0 | 142 |
return ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} |
0 | 144 |
|
145 |
return get_archive_template(); |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Retrieve path of author template in current or parent template. |
|
150 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
* 1. author-{nicename}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
* 2. author-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* 3. author.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* 1. author-john.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* 2. author-1.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* 3. author.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'author'. |
5 | 165 |
* |
0 | 166 |
* @since 1.5.0 |
167 |
* |
|
5 | 168 |
* @see get_query_template() |
169 |
* |
|
170 |
* @return string Full path to author template file. |
|
0 | 171 |
*/ |
172 |
function get_author_template() { |
|
173 |
$author = get_queried_object(); |
|
174 |
||
175 |
$templates = array(); |
|
176 |
||
5 | 177 |
if ( $author instanceof WP_User ) { |
0 | 178 |
$templates[] = "author-{$author->user_nicename}.php"; |
179 |
$templates[] = "author-{$author->ID}.php"; |
|
180 |
} |
|
181 |
$templates[] = 'author.php'; |
|
182 |
||
183 |
return get_query_template( 'author', $templates ); |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Retrieve path of category template in current or parent template. |
|
188 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* 1. category-{slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* 2. category-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* 3. category.php |
0 | 194 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* 1. category-news.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* 2. category-2.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* 3. category.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'category'. |
5 | 203 |
* |
0 | 204 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* @since 4.7.0 The decoded form of `category-{slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* template hierarchy when the category slug contains multibyte characters. |
0 | 207 |
* |
5 | 208 |
* @see get_query_template() |
209 |
* |
|
210 |
* @return string Full path to category template file. |
|
0 | 211 |
*/ |
212 |
function get_category_template() { |
|
213 |
$category = get_queried_object(); |
|
214 |
||
215 |
$templates = array(); |
|
216 |
||
217 |
if ( ! empty( $category->slug ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
$slug_decoded = urldecode( $category->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
if ( $slug_decoded !== $category->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
$templates[] = "category-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
|
0 | 224 |
$templates[] = "category-{$category->slug}.php"; |
225 |
$templates[] = "category-{$category->term_id}.php"; |
|
226 |
} |
|
227 |
$templates[] = 'category.php'; |
|
228 |
||
229 |
return get_query_template( 'category', $templates ); |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* Retrieve path of tag template in current or parent template. |
|
234 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* 1. tag-{slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* 2. tag-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* 3. tag.php |
0 | 240 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* 1. tag-wordpress.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* 2. tag-3.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* 3. tag.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'tag'. |
5 | 249 |
* |
0 | 250 |
* @since 2.3.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @since 4.7.0 The decoded form of `tag-{slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* template hierarchy when the tag slug contains multibyte characters. |
0 | 253 |
* |
5 | 254 |
* @see get_query_template() |
255 |
* |
|
256 |
* @return string Full path to tag template file. |
|
0 | 257 |
*/ |
258 |
function get_tag_template() { |
|
259 |
$tag = get_queried_object(); |
|
260 |
||
261 |
$templates = array(); |
|
262 |
||
263 |
if ( ! empty( $tag->slug ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
$slug_decoded = urldecode( $tag->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
if ( $slug_decoded !== $tag->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
$templates[] = "tag-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
|
0 | 270 |
$templates[] = "tag-{$tag->slug}.php"; |
271 |
$templates[] = "tag-{$tag->term_id}.php"; |
|
272 |
} |
|
273 |
$templates[] = 'tag.php'; |
|
274 |
||
275 |
return get_query_template( 'tag', $templates ); |
|
276 |
} |
|
277 |
||
278 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* Retrieve path of custom taxonomy term template in current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
* The hierarchy for this template looks like: |
0 | 282 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* 1. taxonomy-{taxonomy_slug}-{term_slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
* 2. taxonomy-{taxonomy_slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* 3. taxonomy.php |
0 | 286 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* An example of this is: |
0 | 288 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* 1. taxonomy-location-texas.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
* 2. taxonomy-location.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
* 3. taxonomy.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'taxonomy'. |
5 | 295 |
* |
0 | 296 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* template hierarchy when the term slug contains multibyte characters. |
0 | 299 |
* |
5 | 300 |
* @see get_query_template() |
301 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* @return string Full path to custom taxonomy term template file. |
0 | 303 |
*/ |
304 |
function get_taxonomy_template() { |
|
305 |
$term = get_queried_object(); |
|
306 |
||
307 |
$templates = array(); |
|
308 |
||
309 |
if ( ! empty( $term->slug ) ) { |
|
310 |
$taxonomy = $term->taxonomy; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
$slug_decoded = urldecode( $term->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
if ( $slug_decoded !== $term->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
$templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
|
0 | 317 |
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; |
318 |
$templates[] = "taxonomy-$taxonomy.php"; |
|
319 |
} |
|
320 |
$templates[] = 'taxonomy.php'; |
|
321 |
||
322 |
return get_query_template( 'taxonomy', $templates ); |
|
323 |
} |
|
324 |
||
325 |
/** |
|
326 |
* Retrieve path of date template in current or parent template. |
|
327 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'date'. |
5 | 330 |
* |
0 | 331 |
* @since 1.5.0 |
332 |
* |
|
5 | 333 |
* @see get_query_template() |
334 |
* |
|
335 |
* @return string Full path to date template file. |
|
0 | 336 |
*/ |
337 |
function get_date_template() { |
|
338 |
return get_query_template('date'); |
|
339 |
} |
|
340 |
||
341 |
/** |
|
342 |
* Retrieve path of home template in current or parent template. |
|
343 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'home'. |
0 | 346 |
* |
347 |
* @since 1.5.0 |
|
348 |
* |
|
5 | 349 |
* @see get_query_template() |
350 |
* |
|
351 |
* @return string Full path to home template file. |
|
0 | 352 |
*/ |
353 |
function get_home_template() { |
|
354 |
$templates = array( 'home.php', 'index.php' ); |
|
355 |
||
356 |
return get_query_template( 'home', $templates ); |
|
357 |
} |
|
358 |
||
359 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* Retrieve path of front page template in current or parent template. |
0 | 361 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'frontpage'. |
0 | 364 |
* |
365 |
* @since 3.0.0 |
|
366 |
* |
|
5 | 367 |
* @see get_query_template() |
368 |
* |
|
369 |
* @return string Full path to front page template file. |
|
0 | 370 |
*/ |
371 |
function get_front_page_template() { |
|
372 |
$templates = array('front-page.php'); |
|
373 |
||
374 |
return get_query_template( 'front_page', $templates ); |
|
375 |
} |
|
376 |
||
377 |
/** |
|
378 |
* Retrieve path of page template in current or parent template. |
|
379 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* 1. {Page Template}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* 2. page-{page_name}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* 3. page-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* 4. page.php |
0 | 386 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* 1. page-templates/full-width.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* 2. page-about.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* 3. page-4.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* 4. page.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'page'. |
5 | 396 |
* |
0 | 397 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
* @since 4.7.0 The decoded form of `page-{page_name}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
* template hierarchy when the page name contains multibyte characters. |
0 | 400 |
* |
5 | 401 |
* @see get_query_template() |
402 |
* |
|
403 |
* @return string Full path to page template file. |
|
0 | 404 |
*/ |
405 |
function get_page_template() { |
|
406 |
$id = get_queried_object_id(); |
|
407 |
$template = get_page_template_slug(); |
|
408 |
$pagename = get_query_var('pagename'); |
|
409 |
||
410 |
if ( ! $pagename && $id ) { |
|
411 |
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
|
412 |
$post = get_queried_object(); |
|
413 |
if ( $post ) |
|
414 |
$pagename = $post->post_name; |
|
415 |
} |
|
416 |
||
417 |
$templates = array(); |
|
418 |
if ( $template && 0 === validate_file( $template ) ) |
|
419 |
$templates[] = $template; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
if ( $pagename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
$pagename_decoded = urldecode( $pagename ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
if ( $pagename_decoded !== $pagename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
$templates[] = "page-{$pagename_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
$templates[] = "page-{$pagename}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
} |
0 | 427 |
if ( $id ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
$templates[] = "page-{$id}.php"; |
0 | 429 |
$templates[] = 'page.php'; |
430 |
||
431 |
return get_query_template( 'page', $templates ); |
|
432 |
} |
|
433 |
||
434 |
/** |
|
435 |
* Retrieve path of search template in current or parent template. |
|
436 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'search'. |
5 | 439 |
* |
0 | 440 |
* @since 1.5.0 |
441 |
* |
|
5 | 442 |
* @see get_query_template() |
443 |
* |
|
444 |
* @return string Full path to search template file. |
|
0 | 445 |
*/ |
446 |
function get_search_template() { |
|
447 |
return get_query_template('search'); |
|
448 |
} |
|
449 |
||
450 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* Retrieve path of single template in current or parent template. Applies to single Posts, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* single Attachments, and single custom post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* 1. {Post Type Template}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* 2. single-{post_type}-{post_name}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* 3. single-{post_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* 4. single.php |
0 | 460 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* 1. templates/full-width.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* 2. single-post-hello-world.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* 3. single-post.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* 4. single.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'single'. |
5 | 470 |
* |
0 | 471 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
* @since 4.4.0 `single-{post_type}-{post_name}.php` was added to the top of the template hierarchy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
* @since 4.7.0 The decoded form of `single-{post_type}-{post_name}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* template hierarchy when the post name contains multibyte characters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @since 4.7.0 {Post Type Template}.php was added to the top of the template hierarchy. |
0 | 476 |
* |
5 | 477 |
* @see get_query_template() |
478 |
* |
|
479 |
* @return string Full path to single template file. |
|
0 | 480 |
*/ |
481 |
function get_single_template() { |
|
482 |
$object = get_queried_object(); |
|
483 |
||
484 |
$templates = array(); |
|
485 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
if ( ! empty( $object->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
$template = get_page_template_slug( $object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
if ( $template && 0 === validate_file( $template ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
$templates[] = $template; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
$name_decoded = urldecode( $object->post_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
if ( $name_decoded !== $object->post_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
$templates[] = "single-{$object->post_type}-{$name_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$templates[] = "single-{$object->post_type}-{$object->post_name}.php"; |
0 | 498 |
$templates[] = "single-{$object->post_type}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
|
0 | 501 |
$templates[] = "single.php"; |
502 |
||
503 |
return get_query_template( 'single', $templates ); |
|
504 |
} |
|
505 |
||
506 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
* Retrieves an embed template path in the current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* 1. embed-{post_type}-{post_format}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* 2. embed-{post_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* 3. embed.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* 1. embed-post-audio.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* 2. embed-post.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* 3. embed.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'embed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* @see get_query_template() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* @return string Full path to embed template file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
function get_embed_template() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$object = get_queried_object(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
$templates = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
if ( ! empty( $object->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
$post_format = get_post_format( $object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
if ( $post_format ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
$templates[] = "embed-{$object->post_type}-{$post_format}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
$templates[] = "embed-{$object->post_type}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
$templates[] = "embed.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
return get_query_template( 'embed', $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
* Retrieves the path of the singular template in current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'singular'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
* @see get_query_template() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
* @return string Full path to singular template file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
function get_singular_template() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
return get_query_template( 'singular' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
/** |
0 | 565 |
* Retrieve path of attachment template in current or parent template. |
566 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* 1. {mime_type}-{sub_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
* 2. {sub_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* 3. {mime_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* 4. attachment.php |
0 | 573 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* An example of this is: |
0 | 575 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* 1. image-jpeg.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* 2. jpeg.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
* 3. image.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* 4. attachment.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'attachment'. |
5 | 583 |
* |
0 | 584 |
* @since 2.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
* @since 4.3.0 The order of the mime type logic was reversed so the hierarchy is more logical. |
0 | 586 |
* |
5 | 587 |
* @see get_query_template() |
588 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* @global array $posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* |
5 | 591 |
* @return string Full path to attachment template file. |
0 | 592 |
*/ |
593 |
function get_attachment_template() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
$attachment = get_queried_object(); |
0 | 595 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
$templates = array(); |
0 | 597 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
if ( $attachment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
} |
0 | 604 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
if ( ! empty( $subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
$templates[] = "{$type}-{$subtype}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
$templates[] = "{$subtype}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
$templates[] = "{$type}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
$templates[] = 'attachment.php'; |
0 | 612 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
return get_query_template( 'attachment', $templates ); |
0 | 614 |
} |
615 |
||
616 |
/** |
|
617 |
* Retrieve the name of the highest priority template file that exists. |
|
618 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* so that themes which inherit from a parent theme can just overload one file. |
0 | 621 |
* |
622 |
* @since 2.7.0 |
|
623 |
* |
|
624 |
* @param string|array $template_names Template file(s) to search for, in order. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* @param bool $load If true the template file will be loaded if it is found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. |
0 | 627 |
* @return string The template filename if one is located. |
628 |
*/ |
|
629 |
function locate_template($template_names, $load = false, $require_once = true ) { |
|
630 |
$located = ''; |
|
631 |
foreach ( (array) $template_names as $template_name ) { |
|
632 |
if ( !$template_name ) |
|
633 |
continue; |
|
634 |
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
|
635 |
$located = STYLESHEETPATH . '/' . $template_name; |
|
636 |
break; |
|
5 | 637 |
} elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { |
0 | 638 |
$located = TEMPLATEPATH . '/' . $template_name; |
639 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
$located = ABSPATH . WPINC . '/theme-compat/' . $template_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
break; |
0 | 643 |
} |
644 |
} |
|
645 |
||
646 |
if ( $load && '' != $located ) |
|
647 |
load_template( $located, $require_once ); |
|
648 |
||
649 |
return $located; |
|
650 |
} |
|
651 |
||
652 |
/** |
|
653 |
* Require the template file with WordPress environment. |
|
654 |
* |
|
655 |
* The globals are set up for the template file to ensure that the WordPress |
|
656 |
* environment is available from within the function. The query variables are |
|
657 |
* also available. |
|
658 |
* |
|
659 |
* @since 1.5.0 |
|
660 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @global array $posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
* @global WP_Post $post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
* @global bool $wp_did_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
* @global WP_Query $wp_query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
* @global WP_Rewrite $wp_rewrite |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
* @global string $wp_version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* @global WP $wp |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* @global int $id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
* @global WP_Comment $comment |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
* @global int $user_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
* |
0 | 673 |
* @param string $_template_file Path to template file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* @param bool $require_once Whether to require_once or require. Default true. |
0 | 675 |
*/ |
676 |
function load_template( $_template_file, $require_once = true ) { |
|
677 |
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
|
678 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
if ( is_array( $wp_query->query_vars ) ) { |
0 | 680 |
extract( $wp_query->query_vars, EXTR_SKIP ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
} |
0 | 682 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
if ( isset( $s ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
$s = esc_attr( $s ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
if ( $require_once ) { |
0 | 688 |
require_once( $_template_file ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
} else { |
0 | 690 |
require( $_template_file ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
} |
0 | 692 |
} |