gpt4 book ai didi

php - Magento2 为产品图片添加动态背景

转载 作者:行者123 更新时间:2023-11-28 02:16:49 25 4
gpt4 key购买 nike

我正在 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 中的。

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

最佳答案

你必须像下面这样在 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>

关于php - Magento2 为产品图片添加动态背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48433492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com