检索当前或父模板中的附件模板的路径。
原型
get_attachment_template()
描述
此模板的层次结构如下所示:
参考:
- get_query_template()
返回值
(string)
附件模板文件的完整路径。
源文件
路径:wp-includes/template.php
<?php
...
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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_attachment_template/