【问题标题】:Magento2 adding dynamic background to product imagesMagento2 为产品图片添加动态背景
【发布时间】:2018-07-04 03:33:37
【问题描述】:

我正在 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 中,我无法弄清楚。

对此的一些指导/提示将帮助我实现我正在尝试做的事情。

【问题讨论】:

    标签: php css image magento magento2


    【解决方案1】:

    你必须在 head 标签上方写下 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>
    

    【讨论】:

      猜你喜欢
      • 2023-02-08
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多