_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
查看更多 >