| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Random image in head.tpl | ||||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||||
|
|||||||||
Random image in head.tpl
Hello! Wondering if there is a way to have one of the images in the "head.tpl" template to be randomly placed. We have 50+ variations of a single image (all the same size) and we just want a new one displayed randomly every time the page is loaded. It's not a critical addition, but it would add some nice flair to the site. This is our last piece of the puzzle before launch. xCart did everything we wanted and more.
Heather |
|||||||||
#2
|
|||||||
|
|||||||
hzellers
this is possible if you load the images that you wish to work with into an array in one of the php files that are included in the basic store. Something in func.php would do the job. Then get that script to select one at random. The head.tpl would then just call the variable name as the img source and hey presto. Something along the lines of: Code:
Then in head.tpl replace Code:
Code:
Please note that I haven't tested this but there is no reason why it shouldn't work. Just add your images to the array and away you go. hth
__________________
ex x-cart guru |
|||||||
#3
|
|||||||||
|
|||||||||
Thanks for the tip, I think we're on the right path. But, when I did the code as listed above, every page went blank...not just a missing image, but missing everything. Any thoughts?
Thanks for your help! Do you have a donation box? Heather |
|||||||||
#4
|
|||||||||
|
|||||||||
Duh, it might help if I cut and paste correctly. Jeesh, hours are gettin' to me. It works like a charm...thank you, it adds some great flavor to the site. We launch the new site tonight!
Heather |
|||||||||
#5
|
|||||||
|
|||||||
Heather
Glad it worked.
__________________
ex x-cart guru |
|||||||
#6
|
|||||||
|
|||||||
funky, i tried your code. added the random at the end of fun in the include didn't work but now I get a
INVALID SQL: 1054 : Unknown column 'discount' in 'where clause' SQL QUERY FAILURE: SELECT * FROM xcart_products,xcart_pricing WHERE forsale='Y' AND avail>0 AND xcart_products.productid=xcart_pricing.productid AND discount > 0 ORDER BY RAND() LIMIT 6 at the top of the header. for my site, went back to the original code and still comes up this way, any idea why? http://www.indysuperbikes.com/xcart/customer/home.php |
|||||||
#7
|
|||||||
|
|||||||
got it to work, but would still like to know how to create a random image with a click to the actual product where the welcome area is on the site.
thanks for the help |
|||||||
#8
|
|||||||
|
|||||||
Correction to an error in the code...
Instead of:
$totalImages = array ("image1.gif","image2.gif","image3.gif"); $imagesCount = count ($totalImages ); srand ((double) microtime () * 1000000); $number = rand(0,$imagesCount); $randomImage = $totalImages [$number]; $smarty->assign("headimage",$randomImage); It should be: $totalImages = array ("image1.gif","image2.gif","image3.gif"); $imagesCount = count ($totalImages ); srand ((double) microtime () * 1000000); $number = rand(0,$imagesCount - 1); $randomImage = $totalImages [$number]; $smarty->assign("headimage",$randomImage); Please note the following change: $number = rand(0,$imagesCount); To $number = rand(0,$imagesCount - 1); This will prevent going out of bounds on the array...so you don't get that icky "X" image not found graphic. Thank you, Tracy McClarnon |
|||||||
#9
|
|||||||
|
|||||||
a good point well made
__________________
ex x-cart guru |
|||||||
#10
|
|||||||
|
|||||||
Nice script, but I'd like one that make the random images 'clickable' to a specified page/url. Got a fix for this to above script?
|
|||||||
|
|||
X-Cart forums © 2001-2020
|