X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Shortest random image method (https://forum.x-cart.com/showthread.php?t=4686)

groovico 10-09-2003 04:22 AM

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.

B00MER 10-09-2003 06:21 AM

...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!

Jerrad 01-30-2005 09:47 AM

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!

rorktor1 04-21-2005 08:49 AM

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

august 04-21-2005 07:16 PM

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

Remember the literal statement.

groovico 04-22-2005 05:23 PM

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.

august 04-22-2005 05:47 PM

Sorry, is for the link that I post, it use Java


All times are GMT -8. The time now is 08:24 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.