Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Random image in head.tpl

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-18-2003, 10:47 PM
  hzellers's Avatar 
hzellers hzellers is offline
 

Senior Member
  
Join Date: Mar 2003
Location: Cortland, New York
Posts: 106
 

Default 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
Reply With Quote
  #2  
Old 03-18-2003, 11:08 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

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:
$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);

Then in head.tpl replace
Code:
[img]{$ImagesDir}/logo.gif[/img]
with:
Code:
[img]{$ImagesDir}/{$headimage}[/img]

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
Reply With Quote
  #3  
Old 03-19-2003, 06:15 AM
  hzellers's Avatar 
hzellers hzellers is offline
 

Senior Member
  
Join Date: Mar 2003
Location: Cortland, New York
Posts: 106
 

Default

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
Reply With Quote
  #4  
Old 03-19-2003, 06:26 AM
  hzellers's Avatar 
hzellers hzellers is offline
 

Senior Member
  
Join Date: Mar 2003
Location: Cortland, New York
Posts: 106
 

Default

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
Reply With Quote
  #5  
Old 03-19-2003, 07:08 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Heather

Glad it worked.
__________________
ex x-cart guru
Reply With Quote
  #6  
Old 06-25-2003, 10:18 AM
 
need300z need300z is offline
 

Member
  
Join Date: May 2003
Posts: 16
 

Default

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
Reply With Quote
  #7  
Old 06-25-2003, 10:25 AM
 
need300z need300z is offline
 

Member
  
Join Date: May 2003
Posts: 16
 

Default

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
Reply With Quote
  #8  
Old 07-17-2003, 09:14 AM
 
personalplaythings.com personalplaythings.com is offline
 

Member
  
Join Date: Jul 2003
Posts: 22
 

Default 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
Reply With Quote
  #9  
Old 07-17-2003, 09:24 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

a good point well made
__________________
ex x-cart guru
Reply With Quote
  #10  
Old 07-31-2003, 08:44 PM
 
dennx dennx is offline
 

Member
  
Join Date: Jul 2003
Posts: 10
 

Default

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?
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:02 AM.

   

 
X-Cart forums © 2001-2020