1

我为我的 wordpress 主题启用了自定义背景,如下所示:

add_theme_support('custom-background', array(
    'default-color' => 'FFF',
    'default-image' => get_template_directory_uri() . '/img/bg.jpg'
));

比我抓住身体的类“.custom-background”,因为我想改变背景大小:

body.custom-background {
    background-attachment: fixed!important;
    background-position: center center!important;
    background-repeat: no-repeat!important;
    background-size: cover!important;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    position: absolute;
}

我将它定位为绝对的唯一原因是,因为我想添加一个具有相同背景属性但宽度为 1000 像素和居中边距(0 自动)的其他背景,以使用 css-filters 模糊此部分:

body.custom-background:before {
    content: "";
    background-image: url(""); //here he should takes the custom background-image (of body.custom-background)
    background-attachment: fixed!important;
    background-position: center center!important;
    background-repeat: no-repeat!important;
    background-size: cover!important;
    height: 100%;
    right: 0;
    left: 0;
    margin: 0 auto;
    width: 1000px;
    position: fixed;
    z-index: -1;
    filter: blur(10px);
}

但当然 wp 不知道哪个是背景图像......那么,我该如何解决这个问题 - 他再次将自定义背景图像带到 :before 选择器?

希望你明白我的意思。

4

1 回答 1

0

您可以在 header.php 中编写以下代码

<?php $background = set_url_scheme( get_background_image() ); ?>  
<style>  
  body.custom-background:before {  
  content: "";  
  background-image: url("<?php print $background; ?>");  
  background-attachment: fixed!important;  
  background-position: center center!important;  
  background-repeat: no-repeat!important;  
  background-size: cover!important;  
  height: 100%;  
  right: 0;  
  left: 0;  
  margin: 0 auto;  
  width: 1000px;  
  position: fixed;  
  z-index: -1;  
  filter: blur(10px);  
 }  
</style>  

这将工作...

于 2014-12-12T20:35:40.580 回答