php - 如何从 Redux Framework color_rgba-type 设置 rgba 背景颜色?
问题描述
我正在尝试在我的主题设置中添加一个选项,以使用 Redux Framework 设置我的移动菜单的背景颜色。我使用了 color_rgba 类型,所以我可以选择不透明的颜色。
我在菜单上看到我的背景颜色设置为“mobile-menu”类,但只有一个 HEX 值。
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 颜色而不是 HEX 颜色?
解决方案
我没有使用输出来生成我的样式,因为我在一个单独的 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'].';
}';
}
如您所见,我在最后调用另一个数组,就像这样[rgba]
我的猜测可能是尝试我的方式,或者在默认数组中添加一个 RGBA 值,如下所示:
'default' => array(
'color' => '#E2E2E2',
'alpha' => 1,
'rgba' => 'RGBA VALUE HERE'
),
我希望这会有所帮助。
推荐阅读
- android - 如何停止回收器适配器内的小部件的动画,位置可能会改变?
- sql - 按用户查询报表和分组并统计特定字段
- jquery - 如果我在jquery中选中子复选框,我正在尝试动态检查与子相关的特定父复选框
- groovy - 在参数中接受多个目录并使用 args groovy 合并到单个文件中
- c# - 如何降级内部nuget包的版本
- microsoft-graph-api - 如何使动态生成的不记名令牌工作
- dacpac - azure 中的 Dacpac 部署将值称为无效的列名
- r - 连接到 Twitter 时如何创建用于身份验证的令牌 - 令牌无效或过期
- python - Python Pandas df 问题:“空数据帧的绑定方法 NDFrame.head”
- javascript - 从 2 个不同的文本字段将 2 个值从 php 传递到 ajax