2017-02-22 70 views
1

我函数是这样的:

function abc(){ 

if (of_get_option('pattern_option') != '') { 

    $pattern = of_get_option('pattern_option'); 

    $custom_pattern = ' 

    html{ 
     background: url('.echo $pattern .') repeat !important; 
    } 
    .page_site{ 
     background: url($pattern) repeat !important; 
    } 
    '; 
}; 
}; 

我怎么能呼应背景的URL,我尝试在许多方面并没有什么帮助,总是得到解析错误。

感谢您的时间

+0

感谢-1 ...点击更多:/ – Wordica

+0

我讨厌谁downvote没有人解释为什么男人。返回主题。你有没有试过这个:background:url('。$ pattern。')repeat!important;和背景:url('。$ pattern。')repeat!important; – Oliver

+0

是的,试试吧.... – Wordica

回答

1

您需要使用. operator将您的$pattern变量连接到字符串本身。

所以,换句话说,

$custom_pattern = ' 
    html{ 
     background: url('.$pattern.') repeat !important; 
    } 
    .page_site{ 
     background: url('.$pattern.') repeat !important; 
    } 
'; 
+0

我试试它,但模式不显示。 – Wordica

+0

但你说这是正确的方式,我必须在其他地方搜索“bug”? – Wordica

+0

是@michael,我会说它应该可以工作,但是你必须检查'of_get_option('pattern_option')'在寻找你期望的值。 :-) – ninetwozero

0
if (of_get_option('pattern_option') != '') { 

$pattern = of_get_option('pattern_option'); 

$custom_pattern = ' 
    html{ 
    background: url('. $pattern .') repeat !important; 
    } 
    .page_site{ 
    background: url(' . $pattern . ') repeat !important; 
    }'; 
} 

试试这样。

0
function abc() { 
    if (of_get_option('pattern_option') != '') { 
     $pattern = of_get_option('pattern_option'); 

     $custom_pattern = 'html {'; 
     $custom_pattern .= ' background: url(' . $pattern . ') repeat !important;'; 
     $custom_pattern .= '}'; 
     $custom_pattern .= '.page_site {'; 
     $custom_pattern .= ' background: url('. $pattern . ') repeat !important;'; 
     $custom_pattern .= '}'; 
    } 
}