PHP数组在HTML标记中显示值,但不在CSS选择器(Wordpress)中显示值?
我将按照教程创建自定义Wordpress选项 theme/functions/admin-menu.php中更改背景颜色的函数:PHP数组在HTML标记中显示值,但不在CSS选择器(Wordpress)中显示值?,css,wordpress,Css,Wordpress,我将按照教程创建自定义Wordpress选项 theme/functions/admin-menu.php中更改背景颜色的函数: // Color Scheme function color_scheme_setting() { $options = get_option('plugin_options'); $items = array("Red", "Green", "Blue"); echo "<
// Color Scheme
function color_scheme_setting() {
$options = get_option('plugin_options');
$items = array("Red", "Green", "Blue");
echo "<select name='plugin_options[color_scheme]'>";
foreach ($items as $item) {
$selected = ( $options['color_scheme'] === $item ) ? 'selected = "selected"' : '';
echo "<option value='$item' $selected>$item</option>";
}
echo "</select>";
}
而
标签改变了颜色
为什么它在
标记之间不起作用?只有在呈现
元素后,$options
变量才会初始化。当您想在
块中使用它时,它的值还不可用
您可能希望更早地初始化该变量:
<?php $options = get_option('plugin_options'); ?>
<style>
body {
background: <?php echo $options['color_scheme']; ?>
}
</style>
身体{
背景:
}
<p style="color: <?php echo $options['color_scheme']; ?>"><?php echo $options['color_scheme']; ?></p>
<?php $options = get_option('plugin_options'); ?>
<style>
body {
background: <?php echo $options['color_scheme']; ?>
}
</style>