0

在我的模板上,我有许多字段,用户可以在其中选择并从几个选项中进行选择,以用作其网站的背景。

有两个单独的背景,从 和 的 ID 调用background-onebackground-two存储在单独的数组中。

输出第一个背景:

<?php $background = of_get_option('background-one'); {  
    if ($background['color'] && $background['image']) {
    echo 'body {
    background: ' . $background['color'] . ' url(' . $background['image']. ') ' .$background['repeat']. ' ' .$background['position']. ' ' .$background['attachment']. ';';
echo '
}';
    }

    else if ($background['color']) {  
    echo 'body {
    background: ' . $background['color']. ';';
    echo '
}';         
    }

    else if ($background['image']) {
    echo 'body {
    background: ' . 'url(' . $background['image']. ') ' .$background['repeat']. ' ' .$background['position']. ' ' .$background['attachment']. ';';
    echo '
}'; 
    };
}
?>

但是,由于我对 PHP 非常陌生,我的问题是如何输出第二个背景?

4

1 回答 1

2
<?php 
    $backgroundArray1 = of_get_option('background-one');
    $backgroundArray2 = of_get_option('background-two'); 
    $backgroundText = false;

    if($backgroundArray1['image'] && $backgroundArray2['image'])
    {
      $backgroundText = 'background: url(images/' . $backgroundArray1['image'] . ') no-repeat top center scroll, url(images/' . $backgroundArray1['image'] . '.jpg) repeat top left scroll;';
    }
    else if($backgroundArray1['color'] && $backgroundArray2['color']) 
    {
       $backgroundText = 'background: linear-gradient(to bottom, #'.backgroundArray1['color'].', #'.backgroundArray2['color'].')';
    }
    else if($backgroundArray1['color'] && $backgroundArray1['image']) 
    {
      $backgroundText = 'background: ' . $backgroundArray1['color'] . ' url(' . $backgroundArray1['image'] . ') ' . $backgroundArray1['repeat']. ' ' .$backgroundArray1['position']. ' ' .$backgroundArray1['attachment']. ';';
    }
    else if($backgroundArray1['color']) 
    {  
      $backgroundText = 'background: ' . $backgroundArray1['color']. ';';
    }
    else if($backgroundArray1['image']) 
    {
      $backgroundText = 'background: ' . 'url(' . $backgroundArray1['image']. ') ' .$backgroundArray1['repeat']. ' ' .$backgroundArray1['position']. ' ' .$background['attachment']. ';';
    }

    if($backgroundText)
    {
      echo "body { " . $backgroundText . " } ";
    }
}
?>
于 2013-01-06T06:53:01.423 回答