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
檢視更多 >