get_embed_template

函数
get_embed_template ( No parameters )
返回值
  • (string) Full path to embed template file.
相关
  • get_query_template()
定义位置
相关方法
get_home_templateget_paged_templateget_date_templateget_templateget_page_template
引入
4.5.0
弃用
-

get_embed_template: 这个函数用来检索当前WordPress主题的嵌入模板文件的路径。嵌入模板文件通常用于显示来自其他网站的嵌入内容。

在当前或父模板中检索一个嵌入模板路径。

这个模板的层次结构看起来像:
1. embed-{post_type}-{post_format}.php
2. embed-{post_type}.php
3. embed.php

示例:

1. embed-post-audio.php
2. embed-post.php
3. embed.php

模板层次和模板路径可通过{@see ‘$type_template_hierarchy’}和{@see ‘$type_template’}动态钩子过滤,其中`$type`为’embed’。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_embed_template() {
$object = get_queried_object();
$templates = array();
if ( ! empty( $object->post_type ) ) {
$post_format = get_post_format( $object );
if ( $post_format ) {
$templates[] = "embed-{$object->post_type}-{$post_format}.php";
}
$templates[] = "embed-{$object->post_type}.php";
}
$templates[] = 'embed.php';
return get_query_template( 'embed', $templates );
}
function get_embed_template() { $object = get_queried_object(); $templates = array(); if ( ! empty( $object->post_type ) ) { $post_format = get_post_format( $object ); if ( $post_format ) { $templates[] = "embed-{$object->post_type}-{$post_format}.php"; } $templates[] = "embed-{$object->post_type}.php"; } $templates[] = 'embed.php'; return get_query_template( 'embed', $templates ); }
function get_embed_template() {
	$object = get_queried_object();

	$templates = array();

	if ( ! empty( $object->post_type ) ) {
		$post_format = get_post_format( $object );
		if ( $post_format ) {
			$templates[] = "embed-{$object->post_type}-{$post_format}.php";
		}
		$templates[] = "embed-{$object->post_type}.php";
	}

	$templates[] = 'embed.php';

	return get_query_template( 'embed', $templates );
}

常见问题

FAQs
查看更多 >