wp_get_theme_data_template_parts

函数
wp_get_theme_data_template_parts ( No parameters )
返回值
  • (array) Associative array of `$part_name => $part_data` pairs, with `$part_data` having "title" and "area" fields.
定义位置
相关方法
wp_get_theme_data_custom_templatesget_template_partwp_print_media_templatesget_embed_template_inject_theme_attribute_in_template_part_block
引入
6.4.0
弃用
-

返回主题定义的模板部件的元数据。

function wp_get_theme_data_template_parts() {
	$cache_group    = 'theme_json';
	$cache_key      = 'wp_get_theme_data_template_parts';
	$can_use_cached = ! wp_is_development_mode( 'theme' );

	$metadata = false;
	if ( $can_use_cached ) {
		$metadata = wp_cache_get( $cache_key, $cache_group );
		if ( false !== $metadata ) {
			return $metadata;
		}
	}

	if ( false === $metadata ) {
		$metadata = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_template_parts();
		if ( $can_use_cached ) {
			wp_cache_set( $cache_key, $metadata, $cache_group );
		}
	}

	return $metadata;
}

常见问题

FAQs
查看更多 >