get_single_template
函数
get_single_template ( No parameters )
- 返回值
-
- (string) Full path to single template file.
- 相关
-
- get_query_template()
- 定义位置
-
-
wp-includes/template.php
, line 547
-
wp-includes/template.php
- 引入
- 1.5.0
- 弃用
- –
检索当前或父模板中的单个模板的路径。适用于单个文章。单一附件,和单一自定义文章类型。
这个模板的层次结构看起来像。
- {Post Type Template}.php
- single-{post_type}-{post_name}.php
- single-{post_type}.php
- single.php
这方面的一个例子是
- templates/full-width.php
- single-post-hello-world.php
- single-post.php
- single.php
模板层次和模板路径可通过{@see ‘$type_template_hierarchy’}和{@see ‘$type_template’}动态钩子过滤,其中`$type`为’single’。
function get_single_template() { $object = get_queried_object(); $templates = array(); if ( ! empty( $object->post_type ) ) { $template = get_page_template_slug( $object ); if ( $template && 0 === validate_file( $template ) ) { $templates[] = $template; } $name_decoded = urldecode( $object->post_name ); if ( $name_decoded !== $object->post_name ) { $templates[] = "single-{$object->post_type}-{$name_decoded}.php"; } $templates[] = "single-{$object->post_type}-{$object->post_name}.php"; $templates[] = "single-{$object->post_type}.php"; } $templates[] = 'single.php'; return get_query_template( 'single', $templates ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。