block_template_part

函式
block_template_part ( $part )
引數
  • (string) $part The block template part to print. Use "header" or "footer".
    Required:
定義位置
相關方法
_get_block_templates_pathsget_template_partget_block_templaterender_block_core_template_part_filter_block_template_part_area
引入
5.9.0
棄用
-

block_template_part: 這個函式類似於WordPress中的get_template_part函式,但用於載入特定於塊的模板: 該函式需要兩個引數:區塊型別(例如”core/paragraph”)和模板名稱(例如”content”)。

列印區塊模板部分。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function block_template_part( $part ) {
$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
if ( ! $template_part || empty( $template_part->content ) ) {
return;
}
echo do_blocks( $template_part->content );
}
function block_template_part( $part ) { $template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' ); if ( ! $template_part || empty( $template_part->content ) ) { return; } echo do_blocks( $template_part->content ); }
function block_template_part( $part ) {
	$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
	if ( ! $template_part || empty( $template_part->content ) ) {
		return;
	}
	echo do_blocks( $template_part->content );
}

常見問題

FAQs
檢視更多 >