Magento2为产品图像添加动态背景

时间:2018-01-24 23:42:47

标签: php css image magento magento2

我正在Magento2平台上建立一个网站。 我需要添加艺术家出售的绘画图像。

所需要的是,除了上传图像之外,我还想为绘画添加2-3个预定义的背景图像。 例如 - 餐厅,客厅。

我可以使用此代码在每页加载(随机)上更改背景图像。

<head>
    <style type="text/css">
<!--
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
-->
</style>
</head>

<?php
  $bg = array('SET_A_01_Living.jpg', 'SET_A_02_Bed.jpg', 'SET_A_03_Study.jpg', 'SET_A_04_Dining.jpg' ); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>

但是如何将背景添加到图像和Magento Gallery中,我无法理解。

对此的一些指导/暗示将帮助我实现,我正在尝试做什么。

1 个答案:

答案 0 :(得分:0)

你必须在头标记之上写php,如下所示: -

<?php
  $bg = array('SET_A_01_Living.jpg', 'SET_A_02_Bed.jpg', 'SET_A_03_Study.jpg', 'SET_A_04_Dining.jpg' ); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = $bg[$i]; // set variable equal to which random filename was chosen
?>

<head>
    <style type="text/css">
<!--
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
-->
</style>
</head>