再次在wordpress中添加自定义背景图像

时间:2013-10-13 11:51:20

标签: php css wordpress wordpress-theming background-image

我为我的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;
}

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

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不知道哪个是背景图像...那么,我怎样才能解决这个问题 - 他将自定义背景图像再次放到:选择器之前?

希望你理解我的意思。

1 个答案:

答案 0 :(得分: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>  

这会有用......