We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6531
    • 154 Posts
    I have a gallery on my site which uses an image template variable called ’zThumb’ to display a thumbnail for each document in the gallery. (You can see work in progress here: http://hybridfilms.tv/v2/index.php?id=82)

    We would like the thumbnail to change on every refresh of the page. In other words, every time a visitor comes to the page, they get a random thumbnail. We’ll upload, say, 4 images for each thumbnail, and a different one should be displayed each time the page is generated.

    I am using Ditto to create a gallery with this call:
    [tt][[Ditto?&tpl=`listChildrenTpl` &sortBy=`menuindex` &sortDir=`ASC` &depth=`1` &display=`all` &filter=`hidemenu,0`]][/tt]

    This is listChildrenTpl:
    [tt]<div class="ditto_item" id="ditto_item_[+id+]">
    <div class="ditto_thumb"><a href="[~[+id+]~]">[+zThumb+]</a></div>
    <div class="ditto_pageTitle"><a href="[~[+id+]~]">[+pagetitle+]</a></div>
    <div class="ditto_introText">[+introtext+]</div>
    </div>[/tt]

    Anyone have an idea how to do this?

    Thanks!
      • 3749
      • 24,544 Posts
      This MaxiGallery call will pick a random photo from all galleries and display the thumb as a link to it’s own gallery.

      [[MaxiGallery? &gal_query_ids=`all` &query_level_limit=`5` &order_by=`random` &limit=`1` &pics_per_row=`1` &max_thumb_size=`110`  &thumb_use_dropshadow=`1` &galleryPictureTpl=`mgPicture`]]


      Here’s the mgPicture chunk (which also displays the title and description):

      <div class="picturecontainer">
      <a href="[~[+maxigallery.picture.gal_id+]~]"><img id="maxImage" src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" alt="[+maxigallery.picture.title:htmlent+]" /></a>
      	<p id="maxTitle">[+maxigallery.picture.title:htmlent+]</p>
      	<p id="maxDescr">[+maxigallery.picture.descr:htmlent+]</p>
      </div>


      These should get you close. You’ll probably want to change &gal_query_ids to the id of your gallery and modify the chunk to fit your needs.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting