We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    There are many, many ways to do this, and it’s also possible to add allot of functionality to this. But it’s simple, and it work’s for me. So I just wanted to share it to those who can use it; A way to get random pictures on your site:

    Put this code in a new snippet

    <?php
    echo "<img width=\"XXpx\" height=\"XXpx\" src=\"YOUR PATH". mt_rand(1,20).".jpg\" />";
    ?>


    Where
    (1,20)
    is the number of your first picture in a stock, and the last. You get random pictures between those numbers.

    You have to name your pictures with numbers.

    See it in action here. Here I have 4 folders with pictures named 1 to 40, 41 to 80, 81 to 100 and so on.

    Feel free to use it wherever you want.
      I think, thererfor I am! But what I am, and why...?
      • 18940
      • 152 Posts
      I know this is an old topic but I’m going for it anyway:

      I tried:

      <?php
      echo "<img width=\"180px\" height=\"135px\" src=\"randomimagesmap1/". mt_rand(1,2,3,4).".jpg\" />";
      ?>


      and called it with [[ImageRotator1]] but it keep returning in a bunch of errors and it won’t load my site any further.

      Anyone can tell me what I’ve done wrong there?
        Quality doesn&#39;t need a big signature.
        • 18940
        • 152 Posts
        I found a script that does work in case anyone is looking for a nice image rotator smiley

        <?php
        $Randomimage = array(
           array("Randomimage" => "<img width=\"XXpx\" height=\"XXpx\" src=\"assets/templates/YOURTEMPLATE/imagefolder/image1.jpg\">"),
           array("Randomimage" => "<img width=\"XXpx\" height=\"XXpx\" src=\"assets/templates/YOURTEMPLATE/imagefolder/image2.jpg\">"),
           array("Randomimage" => "<img width=\"XXpx\" height=\"XXpx\" src=\"assets/templates/YOURTEMPLATE/imagefolder/image3.jpg\">")
           );
           function Ausgabe ($Randomimage) {
              echo "$Randomimage";
           }
        
           function zufall($min,$max) {
              srand ((double)microtime()*10000);
              return (rand($min,$max));  
           }
           
           $maxwert = count($Randomimage)-1;  
           $nr = zufall(0,$maxwert);
           $ausgabe = $Randomimage[$nr][Randomimage];
           Ausgabe ($ausgabe);
        ?>


        The only things you need to do is:
        1 Upload the images
        2 Make this snippet and call it (anyway you like using [[SnippetCall]] )
        3 Edit the snippet and point it to the images you want to display. Also you can set the width and height for each particulair image.

        If anyone has a better php snippet please post. For now this works great smiley
          Quality doesn&#39;t need a big signature.
          • 29076
          • 615 Posts
          mDesign, in your snippet you have to many numbers in your mt_rand function. You should only have two, the lowest and the highest you want to pick random numbers from, as I described in my first post.

          Your other example is OK but you’ll have to put in to the array all the images you want to display. At least I wouldn’t work for me, since I have 120 pictures to choose from. But thanks for sharing.
            I think, thererfor I am! But what I am, and why...?
            • 18940
            • 152 Posts
            Okay I see what I did wrong smiley As the website I used it for is already live and kickin’ I’m not going to edit. I keep this topic in mind when making a new site (mostly likely soon smiley )

            Cheers
              Quality doesn&#39;t need a big signature.