We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8822
    • 203 Posts
    Does anyone know how to get Gallery to display the first image in an album by default? I have the following code which is displaying one main image and then a series of thumbnails beneath it. If you click on one of the thumbnails it updates the main image with the selected thumbnail image. This only works though when you click on one of the thumbnails, so when you first go to the page there is no main image (until you select thumb). What is the best way to display the first thumbnail as the main image by default?

    						[[!GalleryItem? &imageWidth=`260`]]
    						[[!+galitem.image:notempty=`
    							<div class="galmainimg">
      								<a href="[[+galitem.image]]"><img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" /></a>
    							</div>
    						`]]
    					
    						[[!Gallery? &album=`[[*gallerylist]]` &toPlaceholder=`gallery` &numThumbs=`4` &thumbWidth=`70` &thumbHeight=`70` ]]
    						[[+gallery]]
    


    Thanks in advance (using Revo 2.2.9)
      • 3109 ☆ A M B ☆
      • 894 Posts
      Just add the id parameter to your GalleryItem call like this:

      
      [[!GalleryItem? &imageWidth=`260` &id=`1`]]
      


      That should always load the first image when you load the page.

      Good Luck.
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 8822
        • 203 Posts
        Sorry, don't know how i missed that in the documentation!!! If the default photo is not always going to be 1 however is there anyway for it to pick the next available image. For example, if you delete the image with id=1 from a gallery and it no longer exists, i don't want to have to update the &id property in galleryitem. Any ideas?
          • 3109 ☆ A M B ☆
          • 894 Posts
          Not that I know of, sorry.
            Benjamin Marte
            Interactive Media Developer
            Follow Me on Twitter | Visit my site | Learn MODX
            • 36426
            • 197 Posts
            Quote from: benmarte at Oct 09, 2013, 12:30 PM
            Just add the id parameter to your GalleryItem call like this:

            
            [[!GalleryItem? &imageWidth=`260` &id=`1`]]
            


            That should always load the first image when you load the page.

            Good Luck.

            Hi I'm also trying to load up the first image but I can't get it to work. Here is my code:

            [[!Gallery? &album=`[[*property-gallery]]` &toPlaceholder=`gallery`]]
            [[!GalleryItem? &id=`1`]]
             
            [[!+galitem.image:notempty=`
            <div class="image">
              <img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" />
            </div>
            `]]
             
            <div style="display: block; position: relative; overflow: hidden; margin: auto;">
            [[!+gallery:notempty=` 
            [[+gallery]]
            `]]
            </div>


            Any ideas how I can get this working? Thanks for any help.
              Yorkshire UK based hosting provider: https://www.simulant.uk
              • 50916
              • 1 Posts
              Did anyone ever figure this out? I too, would like to be able to return the first item in each gallery. So if I have 2 galleries, and each have 5 pictures, the first gallery would return "1" as the default image, and the second gallery would return "6" as the first image in that gallery. I've searched and searched, and can't seem to find anything about it.
                • 36426
                • 197 Posts
                Hi this snippet works:

                <?php
                $path = $modx->getOption('gallery.files_url');
                     
                    $album = $modx->getOption('album', $scriptProperties, false);
                    if (!$album) { return ''; }
                    if ($modx->getOption('checkForRequestVar',$scriptProperties,true)) {
                        $getParam = $modx->getOption('getParam',$scriptProperties,'galItem');
                        if (!empty($_REQUEST[$getParam])) { $id = (int)$_REQUEST[$getParam]; }
                    }
                    if ($id) { return ''; };
                     
                    $sql = "SELECT item.* FROM modx_gallery_items item
                    INNER JOIN modx_gallery_album_items a ON item.id = a.item AND a.rank = 0
                    WHERE a.album = :album";
                     
                    $stmt = $modx->prepare($sql);
                    $stmt->execute(array('album'=> $album));
                    $row = $stmt->fetch(PDO::FETCH_ASSOC);
                    $stmt->closeCursor();
                    $row['fullpath'] = $path . "" . $row['filename'];
                     
                    $modx->toPlaceholders(array('single' => $row));


                Which is then included in your Gallery call like this:

                     
                    [[!Gallery? &album=`[[*gallerytemplatevariable]]` &toPlaceholder=`gallery`]]
                    [[!GalleryItem?]]
                     
                    [[+galitem.image:notempty=`<div class="image">
                     <img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" />
                    </div>`]]
                    [[+galitem:empty=`<div class="image">
                    [[!getFirstImage? &album=`[[*gallerytemplatevariable]]` ]]
                     <img src="[[+single.fullpath]]" alt="[[+single.description]]" />
                    </div>`]]
                     
                     
                    <div style="display: block; position: relative; overflow: hidden; margin: auto;">
                    [[!+gallery:notempty=`
                    [[+gallery]]
                    `]]
                    </div>


                BUT I'm also having a problem with this. Once the gallery album IDs get over 100 it doesn't seem to work... I'm not sure why. Can anyone please help at all?

                Thanks.
                  Yorkshire UK based hosting provider: https://www.simulant.uk