get_block_theme_folders

函式
get_block_theme_folders ( $theme_stylesheet = null )
引數
  • (string) $theme_stylesheet The stylesheet. Default is to leverage the main theme root.
    Required:
    Default: null
返回值
  • (string[]) { Folder names used by block themes. @type string $wp_template Theme-relative directory name for block templates. @type string $wp_template_part Theme-relative directory name for block template parts. }
定義位置
相關方法
_get_block_templates_files_get_block_template_fileget_block_templatesget_block_templateget_block_categories
引入
5.9.0
棄用
-

get_block_theme_folders:此函式返回一個目錄陣列,其中可以儲存特定主題的塊模板。它不接受任何引數。

出於向後相容的原因。

區塊主題可能使用區塊模板或區塊模板-小工具,這個函式確保我們正確地回退到這些資料夾。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_block_theme_folders( $theme_stylesheet = null ) {
$theme_name = null === $theme_stylesheet ? get_stylesheet() : $theme_stylesheet;
$root_dir = get_theme_root( $theme_name );
$theme_dir = "$root_dir/$theme_name";
if ( file_exists( $theme_dir . '/block-templates' ) || file_exists( $theme_dir . '/block-template-parts' ) ) {
return array(
'wp_template' => 'block-templates',
'wp_template_part' => 'block-template-parts',
);
}
return array(
'wp_template' => 'templates',
'wp_template_part' => 'parts',
);
}
function get_block_theme_folders( $theme_stylesheet = null ) { $theme_name = null === $theme_stylesheet ? get_stylesheet() : $theme_stylesheet; $root_dir = get_theme_root( $theme_name ); $theme_dir = "$root_dir/$theme_name"; if ( file_exists( $theme_dir . '/block-templates' ) || file_exists( $theme_dir . '/block-template-parts' ) ) { return array( 'wp_template' => 'block-templates', 'wp_template_part' => 'block-template-parts', ); } return array( 'wp_template' => 'templates', 'wp_template_part' => 'parts', ); }
function get_block_theme_folders( $theme_stylesheet = null ) {
	$theme_name = null === $theme_stylesheet ? get_stylesheet() : $theme_stylesheet;
	$root_dir   = get_theme_root( $theme_name );
	$theme_dir  = "$root_dir/$theme_name";

	if ( file_exists( $theme_dir . '/block-templates' ) || file_exists( $theme_dir . '/block-template-parts' ) ) {
		return array(
			'wp_template'      => 'block-templates',
			'wp_template_part' => 'block-template-parts',
		);
	}

	return array(
		'wp_template'      => 'templates',
		'wp_template_part' => 'parts',
	);
}

常見問題

FAQs
檢視更多 >