We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I have a little random image script:

    <?php
    
    ///assets/images/headers/header-img1.jpg
    
    $images = array(); 
    
    $path = isset($scriptProperties['path']) ? MODX_ASSETS_PATH . $scriptProperties['path'] : MODX_ASSETS_PATH . 'images/';
    
    if(count($images) == 0){
    
      $images = glob($path. '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
    
      }
    
    shuffle($images);
    
    $rand_img = str_replace(MODX_BASE_PATH, '', array_pop($images));
    
    //$key = array_rand($images);
    
    //$rand_img = str_replace(MODX_BASE_PATH, '', $images[$key]);
    
    return $rand_img;





    Pretty simple, grabs a random image from a path, however, if I try to call it more than once in a resource:

    [[!randomImage? &path=`images/sidebars/`]]

    [[!randomImage? &path=`images/sidebars/`]]

    [[!randomImage? &path=`images/sidebars/`]]


    it will return the same image all three times.

    Is this something to do with modx caching?
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525