Php 如何从Redux Framework color_rgba-type设置rgba背景色?
我正在尝试在我的主题设置中添加一个选项,以使用Redux框架设置移动菜单的背景色。 我使用了颜色_rgba类型,因此我可以选择不透明度的颜色 我看到我的菜单上设置了“移动菜单”类的背景色,但只有十六进制值Php 如何从Redux Framework color_rgba-type设置rgba背景色?,php,css,redux-framework,Php,Css,Redux Framework,我正在尝试在我的主题设置中添加一个选项,以使用Redux框架设置移动菜单的背景色。 我使用了颜色_rgba类型,因此我可以选择不透明度的颜色 我看到我的菜单上设置了“移动菜单”类的背景色,但只有十六进制值 Redux::setSection( $opt_name, array( 'title' => __( 'Mobile menu', 'redux-framework-demo' ), 'id' => 'header-mobile-menu
Redux::setSection( $opt_name, array(
'title' => __( 'Mobile menu', 'redux-framework-demo' ),
'id' => 'header-mobile-menu',
'subsection' => true,
'fields' => array(
'id' => 'header-mobile-menu-background',
'type' => 'color_rgba',
'title' => __('Mobile menu background Color', 'redux-framework-demo'),
'subtitle' => __('Background color for mobile menu overlay', 'redux-framework-demo'),
'default' => array(
'color' => '#E2E2E2',
'alpha' => 1
),
'transparent' => false,
'output' => array(
'background-color' => '.mobile-menu',
),
),
) );
如何确保获得rgba颜色而不是十六进制颜色?我没有使用输出生成样式,因为我在单独的PHP文件中处理样式。但我会告诉你我是如何做到的,希望它能帮助你 我认为这也可能是因为在设置中没有使用默认的RGBA值 这是我的字段数组:
array(
'id' => 'the-id-of-my-field-is-here',
'type' => 'color_rgba',
'title' => 'my title of my field setting',
'subtitle' => esc_html__('My subtitle of my field setting', 'redux-framework-demo'),
'transparent' => false,
'default' => array(
'color' => '#E2E2E2',
'alpha' => 1
),
),
在我的单独php文件中,我这样调用我的选项名称:
//This sets my redux settings in a variable called options
$options = get_my_theme_options();
if(!empty($options['the-id-of-my-field-is-here'])) {
echo'.mobile-menu {
background-color: '.$options["the-id-of-my-field-is-here"]['rgba'].';
}';
}
然后我检查我的选项中是否有值,如果有,在我的样式中使用它,如下所示:
//This sets my redux settings in a variable called options
$options = get_my_theme_options();
if(!empty($options['the-id-of-my-field-is-here'])) {
echo'.mobile-menu {
background-color: '.$options["the-id-of-my-field-is-here"]['rgba'].';
}';
}
如您所见,我正在调用末尾的另一个数组,就像这样[rgba]
我的猜测可能是尝试我的方法,或者在默认数组中添加RGBA值,如下所示:
'default' => array(
'color' => '#E2E2E2',
'alpha' => 1,
'rgba' => 'RGBA VALUE HERE'
),
我希望这能有所帮助。基于此参考链接: 假设您希望输出一种颜色作为背景色,而不是颜色。以下键/对格式的输出数组将完成此操作:
'output' => array('background-color' => '.site-header')
或者,可以为不同的选择器指定多个元素
'output' => array(
'background-color' => '.site-header',
'color' => '.site-footer')
还支持多个选择器。用逗号分隔
'output' => array('background-color' => '.site-header, .site-footer')
我试着像你建议的那样添加一个rgba值作为默认值,它确实起了作用。谢谢很高兴你修好了!祝你的主题好运!