WordPress函数文档get_attachment_template()
获取附件页面模版文件attachment.php 描述 译文 检索当前模板或父模板的附件模板路径。 附件路径首…
获取附件页面模版文件attachment.php
描述
译文
检索当前模板或父模板的附件模板路径。
附件路径首先查找mime类型的第一部分是否存在,接着超找第二部分。最后查找由下划线分成的两个类别。如果没有查找到任一部分,可查找’attachment.php’文件并返回。
Mime类别’text/plain’的示例包括’text.php’, ‘plain.php’, 以及 ‘text_plain.php’。
原文
Retrieve path of attachment template in current or parent template.
The attachment path first checks if the first part of the mime type exists. The second check is for the second part of the mime type. The last check is for both types separated by an underscore. If neither are found then the file ‘attachment.php’ is checked and returned.
Some examples for the ‘text/plain’ mime type are ‘text.php’, ‘plain.php’, and finally ‘text_plain.php’.
用法
<?php get_attachment_template() ?>
参数
None.
返回值
(string)
Returns path of attachment template in current or parent template.
注意
- 使用到: get_query_template()
- 使用到 global: (object) $posts a property of the WP_Query object.
历史
添加于 版本: 2.0.0
源文件
get_attachment_template() 函数的代码位于 wp-includes/template.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Retrieve path of attachment template in current or parent template.
*
* The attachment path first checks if the first part of the mime type exists.
* The second check is for the second part of the mime type. The last check is
* for both types separated by an underscore. If neither are found then the file
* ‘attachment.php’ is checked and returned.
*
* Some examples for the ‘text/plain’ mime type are ‘text.php’, ‘plain.php’, and
* finally ‘text-plain.php’.
*
* The template path is filterable via the dynamic {@see ‘$type_template’} hook,
* e.g. ‘attachment_template’.
*
* @since 2.0.0
*
* @see get_query_template()
*
* @global array $posts
*
* @return string Full path to attachment template file.
*/
function get_attachment_template() {
$attachment = get_queried_object();
$templates = array();
if ( $attachment ) {
if ( false !== strpos( $attachment->post_mime_type, ‘/’ ) ) {
list( $type, $subtype ) = explode( ‘/’, $attachment->post_mime_type );
} else {
list( $type, $subtype ) = array( $attachment->post_mime_type, ” );
}
if ( ! empty( $subtype ) ) {
$templates[] = “{$type}-{$subtype}.php”;
$templates[] = “{$subtype}.php”;
}
$templates[] = “{$type}.php”;
}
$templates[] = ‘attachment.php’;
return get_query_template( ‘attachment’, $templates );
}
|
- 原文:http://codex.wordpress.org/Function_Reference/get_attachment_template
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!