主要代码位于底部。
我试图自定义WordPress主题自定义程序并遇到问题。
基本上,可以选择许多背景图像。在下面的代码中,如果选择“微妙”'制作完成后,背景图片网址为url.com/image.png。
然而,如果案件“没有”'如果选中,我希望背景图像拉出从另一个选择器中选择的颜色。例如,我希望它吐出来:
'{background: <?php echo $color_scheme_2; ?>;}'
我知道你不能在回声中使用回声,但我不确定如何正确编码以使其正常工作。
以下是完整代码:
$color_scheme_end2 = get_option( 'color_scheme_end2' );
$example_position = get_theme_mod( 'background_image' );
if( $example_position != '' ) {
switch ( $example_position ) {
case 'nothing':
// ** This is where I want the color_scheme2 to be spit out as the background color **
break;
case 'subtle':
echo '<style type="text/css">';
echo '.site-header {background-image: url("http://www.url.com/image.png/")';
echo '</style>';
break;
非常感谢您提供的任何指导!
答案 0 :(得分:0)
这是你可以更新代码的方法,你可以使用连接运算符(。):
$color_scheme_end2 = get_option( 'color_scheme_end2' );
$example_position = get_theme_mod( 'background_image' );
if( $example_position != '' ) {
switch ( $example_position ) {
case 'nothing':
// ** This is where I want the color_scheme2 to be spit out as the background color **
echo '<style type="text/css">';
echo '.site-header {background: '.$color_scheme_2.';}';
echo '</style>';
break;
case 'subtle':
echo '<style type="text/css">';
echo '.site-header {background-image: url("http://www.url.com/image.png/")';
echo '</style>';
break;