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