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

Shortest random image method

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 10-09-2003, 04:22 AM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default Shortest random image method

Seen lots of debate over random image methods, here's one for the pot

If your on x-cart 3.3.8 or over use

Code:
[img]yoursitepath/image{[/img]

hows this work? Notice the

image{"1"|mt_rand:5}.gif

Generating a random number between 1 and 5 using smarty so in the html it's

image5.gif or image3.gif etc etc

Simply name your images image1.gif, image2.gif, image3.gif etc and set the mtrand:X to the amount you have in the folder.

If your running on an older x-cart then the smarty that is installed doesnt support the random function.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #2  
Old 10-09-2003, 06:21 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

...And if are running an older version of X-cart less than version 3.3.8:

Save the following code to Smarty-2.1.1/plugins/function.random.php.

Note your Smarty-2.1.1 directory may differ.

Code:
<? /* * Smarty plugin * ------------------------------------------------------------- * File: function.random.php * Type: function * Name: random * Author: Ben Godfrey <ben@hypothetical.co.uk> * Purpose: outputs a random number in the range specified by min and max attribs or 0 and mt_randmax * Usage: {random min=0 max=10}, {random min=-10}, {random max=20} or just {random} * ------------------------------------------------------------- */ function smarty_function_random($params, &$smarty) { extract($params); if (empty($min)) $min = 0; if (empty($max)) $max = mt_getrandmax(); // complain about erroneous args if (!is_numeric($min)) { $smarty->trigger_error("random: parameter 'min' must be a number"); return; } if (!is_numeric($max)) { $smarty->trigger_error("random: parameter 'max' must be a number"); return; } print(mt_rand(floor($min), ceil($max))); } // initialise random number sequence mt_srand(time()); ?>

How to use it in .tpls?

Code:
{random min=0 max=10}, {random min=-10}, {random max=20} or just {random}

Kudos!
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #3  
Old 01-30-2005, 09:47 AM
 
Jerrad Jerrad is offline
 

X-Adept
  
Join Date: Nov 2004
Location: The Netherlands
Posts: 484
 

Default

Quiet a old post but the random image method given by
groovico still works great for me. Because I want to have
different images than the product or detailed images
random loaded.

But I also would like it to load several images at the same time
and on the same page, and in a way there are no duplicate
images loaded. Would that be possibe?

Furthermore, is there a way to make the random loaded
images clickable, so that clicking on them will open the
corresponding product page?

I hope that somebody can help or knows another way to
load clickable images other than the product or detailed images.
Thanks in advance!
__________________
X-Cart 4.0.12
Heavy modified with paid, free and forum mods.
PHP 5.2.5 | MYSQL 5.0.51a
Reply With Quote
  #4  
Old 04-21-2005, 08:49 AM
 
rorktor1 rorktor1 is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 41
 

Default

Wow, this is so easy to do its amazing. I was researching how to add a bunch of javascript to do this for the last couple hours until I found this post.

Excellent, fantastic, amazing, easy.

thank you thank you thank you
__________________
X-Cart Newbie!

- X-Cart Gold v4.1.5 and v4.0.17-
Windows 2003 Server, IIS6, PHP 5.2.13
Reply With Quote
  #5  
Old 04-21-2005, 07:16 PM
  august's Avatar 
august august is offline
 

Senior Member
  
Join Date: Jul 2003
Posts: 178
 

Default

http://forum.x-cart.com/viewtopic.php?p=28159&highlight=#28159

Remember the literal statement.
__________________
"The point is, to make so much money, that money isn't the point anymore."

Pro Version 4.0.19
Gold Version 4.1.3
Linux
Reply With Quote
  #6  
Old 04-22-2005, 05:23 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Quote:
Originally Posted by august
http://forum.x-cart.com/viewtopic.php?p=28159&highlight=#28159

Remember the literal statement.

You don't need it for my example above, it's not javascript, it's done in smarty.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #7  
Old 04-22-2005, 05:47 PM
  august's Avatar 
august august is offline
 

Senior Member
  
Join Date: Jul 2003
Posts: 178
 

Default

Sorry, is for the link that I post, it use Java
__________________
"The point is, to make so much money, that money isn't the point anymore."

Pro Version 4.0.19
Gold Version 4.1.3
Linux
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:37 PM.

   

 
X-Cart forums © 2001-2020