I want different backgrounds in the side columns every time the page is reloaded. Left and right will always be different.
Is this possible? If so how?
Thanks in advance,
Gobbo
Using opencart 3.0.3.2 - PHP 7.4 - Standard Template - Add to Cart Enable Disable Out of Stock Product 3.x - Export/Import Tool (V3.22) for OpenCart 3.x - Footer Social Media Link( 3.x ) v1.0
1. Add following function in system/helper/general.php . Please update your image url accordingly.
Code: Select all
function getRandomBackground() {
$images = (
'http://domain.com/images/1.jpg',
'http://domain.com/images/2.jpg',
'http://domain.com/images/3.jpg',
'http://domain.com/images/4.jpg'
);
return $images[array_rand($images)];
}
Code: Select all
<aside id="column-left" class="col-sm-3 hidden-xs" style="background-image:url('<?php echo getRandomBackground();?>')">
XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart
I can put it on the sever side with ease, but out of curiosity how would it got on the client side? Would a addon need to be added?
Using opencart 3.0.3.2 - PHP 7.4 - Standard Template - Add to Cart Enable Disable Out of Stock Product 3.x - Export/Import Tool (V3.22) for OpenCart 3.x - Footer Social Media Link( 3.x ) v1.0
Code: Select all
<script>
function getRandomBackground() {
var images = Array(
'http://domain.com/images/1.jpg',
'http://domain.com/images/2.jpg',
'http://domain.com/images/3.jpg',
'http://domain.com/images/4.jpg'
);
return images[Math.floor(Math.random()*images.length)];
}
$(document).ready(function(){
$('#column-left').css('background-image', 'url("' + getRandomBackground() + '")');
});
</script>
XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart
Where does the text go in 1?
Is it before or after:-
<?php
function token($length = 32) {
// Create token to login with
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$token = '';
for ($i = 0; $i < $length; $i++) {
$token .= $string[mt_rand(0, strlen($string) - 1)];
}
return $token;
}
Using opencart 3.0.3.2 - PHP 7.4 - Standard Template - Add to Cart Enable Disable Out of Stock Product 3.x - Export/Import Tool (V3.22) for OpenCart 3.x - Footer Social Media Link( 3.x ) v1.0
Users browsing this forum: No registered users and 90 guests