render_block_core_widget_group

函数
render_block_core_widget_group ( $attributes, $content, $block )
参数
  • (array) $attributes The block attributes.
    Required:
  • (string) $content The block content.
    Required:
  • (WP_Block) $block The block.
    Required:
返回值
  • (string) Rendered block.
定义位置
相关方法
register_block_core_widget_grouprender_block_core_legacy_widgetrender_block_core_imagerender_block_core_tag_cloudrender_block_core_file
引入
-
弃用
-

render_block_core_widget_group: 这是一个WordPress的核心函数,用于在编辑器中渲染widget group块。它用于在网站的前端输出该块的HTML标记。

渲染”core/widget-group”区块。

function render_block_core_widget_group( $attributes, $content, $block ) {
	global $wp_registered_sidebars, $_sidebar_being_rendered;

	if ( isset( $wp_registered_sidebars[ $_sidebar_being_rendered ] ) ) {
		$before_title = $wp_registered_sidebars[ $_sidebar_being_rendered ]['before_title'];
		$after_title  = $wp_registered_sidebars[ $_sidebar_being_rendered ]['after_title'];
	} else {
		$before_title = '<h2 class="widget-title">';
		$after_title  = '</h2>';
	}

	$html = '';

	if ( ! empty( $attributes['title'] ) ) {
		$html .= $before_title . esc_html( $attributes['title'] ) . $after_title;
	}

	$html .= '<div class="wp-widget-group__inner-blocks">';
	foreach ( $block->inner_blocks as $inner_block ) {
		$html .= $inner_block->render();
	}
	$html .= '</div>';

	return $html;
}

常见问题

FAQs
查看更多 >