We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13622
    • 74 Posts
    Hi,

    I’ve been reading over the documentation for a way to grab a random image from a Album, does anyone have a suggestion? Maybe I missed something.

    Thanks!
      • 6254
      • 6 Posts
      I have the same question... Anyone..?
        • 28215
        • 4,149 Posts
        That feature is not applicable at this time. You can file a Feature Request at http://github.com/splittingred/Gallery/issues/
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • Any update on this one? I tried

          [[!Gallery? &album=`5` &limit=`1` &thumbWidth=`980` &thumbHeight=`153` &toPlaceholder=`AlbumImage` &thumbTpl=`ImageTpl` &albumCoverSort=`random` ]]
          <div id="headline" style="background-image: url('[[+AlbumImage]]');">
          
          </div>


          If I call GalerAlbums, I can’t choose the single album, right?
          • Update and solution:

            I found non documented code which indicated that random can be used:
            if (strcasecmp($sort,'rand')==0) {
                $c->sortby('RAND()',$dir);
            } else {
                $c->sortby($sortAlias.'.'.$sort,$dir);
            }


            So here is my chunk [[$headline]] which puts a random image from a predefined album (5) behind a div box:
            [[!Gallery? &album=`5` &limit=`1` &thumbWidth=`980` &thumbHeight=`153` &sort=`rand` &toPlaceholder=`AlbumImage` &thumbTpl=`ImageTpl` ]]
            <div id="headline" style="background-image: url('[[+AlbumImage]]');">
            
            </div>


            [[$ImageTpl]] is simply:
            [[+thumbnail]]

            which puts out the path to the image in the size of &thumbWidth and &thumbHeight.

            Looks like this: http://bergischer-ring.bytethinker.com/galerie.html

            Cheers,

            Guido

            • sort and dir are both documented and I don’t know how they relate to the albumCoverSort. I would experiment all of these options it may be that there is some clarification to be made in the docs.
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
              • http://rtfm.modx.com/display/ADDON/Gallery.Gallery - no "rand" mentioned, no answer given here in this thread.
                • albumCoverSort was the only documented way to randomize the choice of an image. It uses "random" instead of "rand". So I didnt even hit it by trying.
                    • 4172
                    • 5,888 Posts
                    for this kind of galleries, with only view images for each resource, there is the MIGX-TV as an alternative way.
                    There is a randomize-property for the included getImageList-snippet.
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                    • -.-
                      maybe I need to use this snippet of yours as my "header image gallery" destroys my content galleries.
                      And: the header images are beeing taken from the current content gallery, not from "5" as I defined.