_resolve_home_block_template

函式
_resolve_home_block_template ( No parameters )
Access
Private
返回值
  • (array|null) A template object, or null if none could be found.
定義位置
相關方法
resolve_block_templatelocate_block_templatewp_enable_block_templatesget_block_templateget_the_block_template_html
引入
6.0.0
棄用
-

_resolve_home_block_template: 這個函式用於解決特定網站的首頁模板。它通常在get_option函式中呼叫。

返回網站主頁的正確模板。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _resolve_home_block_template() {
$show_on_front = get_option( 'show_on_front' );
$front_page_id = get_option( 'page_on_front' );
if ( 'page' === $show_on_front && $front_page_id ) {
return array(
'postType' => 'page',
'postId' => $front_page_id,
);
}
$hierarchy = array( 'front-page', 'home', 'index' );
$template = resolve_block_template( 'home', $hierarchy, '' );
if ( ! $template ) {
return null;
}
return array(
'postType' => 'wp_template',
'postId' => $template->id,
);
}
function _resolve_home_block_template() { $show_on_front = get_option( 'show_on_front' ); $front_page_id = get_option( 'page_on_front' ); if ( 'page' === $show_on_front && $front_page_id ) { return array( 'postType' => 'page', 'postId' => $front_page_id, ); } $hierarchy = array( 'front-page', 'home', 'index' ); $template = resolve_block_template( 'home', $hierarchy, '' ); if ( ! $template ) { return null; } return array( 'postType' => 'wp_template', 'postId' => $template->id, ); }
function _resolve_home_block_template() {
	$show_on_front = get_option( 'show_on_front' );
	$front_page_id = get_option( 'page_on_front' );

	if ( 'page' === $show_on_front && $front_page_id ) {
		return array(
			'postType' => 'page',
			'postId'   => $front_page_id,
		);
	}

	$hierarchy = array( 'front-page', 'home', 'index' );
	$template  = resolve_block_template( 'home', $hierarchy, '' );

	if ( ! $template ) {
		return null;
	}

	return array(
		'postType' => 'wp_template',
		'postId'   => $template->id,
	);
}

常見問題

FAQs
檢視更多 >