描述:
获取附件页面模版文件attachment.php
用法:
<?php get_attachment_template() ?>
参数:
此函数不接收参数
源文件:
/**
* 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 );
}