block_core_home_link_build_css_colors

函数
block_core_home_link_build_css_colors ( $context )
参数
  • (array) $context home link block context.
    Required:
返回值
  • (array) Colors CSS classes and inline styles.
定义位置
相关方法
block_core_page_list_build_css_colorsblock_core_navigation_link_build_css_colorsblock_core_home_link_build_css_font_sizesblock_core_navigation_submenu_build_css_colorsblock_core_navigation_build_css_colors
引入
-
弃用
-

block_core_home_link_build_css_colors: 这个函数用来为首页链接块生成CSS颜色样式。它是块编辑器的核心导航块的一部分。

用CSS类和内联样式建立一个数组,定义将被应用于前端的主页链接标记的颜色。

function block_core_home_link_build_css_colors( $context ) {
	$colors = array(
		'css_classes'   => array(),
		'inline_styles' => '',
	);

	// Text color.
	$has_named_text_color  = array_key_exists( 'textColor', $context );
	$has_custom_text_color = isset( $context['style']['color']['text'] );

	// If has text color.
	if ( $has_custom_text_color || $has_named_text_color ) {
		// Add has-text-color class.
		$colors['css_classes'][] = 'has-text-color';
	}

	if ( $has_named_text_color ) {
		// Add the color class.
		$colors['css_classes'][] = sprintf( 'has-%s-color', $context['textColor'] );
	} elseif ( $has_custom_text_color ) {
		// Add the custom color inline style.
		$colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] );
	}

	// Background color.
	$has_named_background_color  = array_key_exists( 'backgroundColor', $context );
	$has_custom_background_color = isset( $context['style']['color']['background'] );

	// If has background color.
	if ( $has_custom_background_color || $has_named_background_color ) {
		// Add has-background class.
		$colors['css_classes'][] = 'has-background';
	}

	if ( $has_named_background_color ) {
		// Add the background-color class.
		$colors['css_classes'][] = sprintf( 'has-%s-background-color', $context['backgroundColor'] );
	} elseif ( $has_custom_background_color ) {
		// Add the custom background-color inline style.
		$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] );
	}

	return $colors;
}

常见问题

FAQs
查看更多 >