get_attachment_template()
get_attachment_template()
在当前模板或父模板中检索附件模板的路径。
Retrieve path of attachment template in current or parent template.
说明(Description)
另见函数 get_query_template()
返回(Return)
(string)附件模板文件的完整路径。
源码(Source)
/** * 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 ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.3.0 | wp-includes/template.php:617 | 0 | 2 |
get_attachment_template() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_attachment_template/