We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36426
    • 197 Posts
    Hi I have this awesome snippet (not sure now who wrote it) that pulls the first gallery album image in so when you click a page with a gallery on the first image shows. As I've added more albums and pages though it has stopped working on the latest ones. The only thing I can see is that the image IDs are over 100... Can anyone please help with a fix so first album images with ID over 100 also are now pulled in?
    <?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));
    
      Yorkshire UK based hosting provider: https://www.simulant.uk
      • 36426
      • 197 Posts
      ps here is my snippet call:

      [[!Gallery? &album=`[[*templatevariableforgallery]]` &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=`[[*templatevariableforgallery]]` ]]
           <img src="[[+single.fullpath]]" alt="[[+single.description]]" />
          </div>`]]
           
           
          <div style="display: block; position: relative; overflow: hidden; margin: auto;">
          [[!+gallery:notempty=`
          [[+gallery]]
          `]]
          </div>
           
          <p> </p>
      [ed. note: jonahnaylor last edited this post 8 years, 7 months ago.]
        Yorkshire UK based hosting provider: https://www.simulant.uk
        • 36426
        • 197 Posts
        Hi can I bump this up. It seems that image IDs over 100 aren't effecting anything. Gallery first images are still showing for some resources/galleries but not others. Can anyone help please? [ed. note: jonahnaylor last edited this post 8 years, 2 months ago.]
          Yorkshire UK based hosting provider: https://www.simulant.uk
          • 3749
          • 24,544 Posts
          I don't see anything obvious unless the problem images don't have rank of 0 (take a look in the DB).
            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
            • 36426
            • 197 Posts
            Hi Bob - thank you!

            Turns out that's exactly what it was. Once I set the first image of each album to rank 0 in the database it displayed as it should.

            What gives the image the rank 0 to begin with and is there a way to adjust the snippet to account for future problems with images that don't have 0 rank? Shouldn't dragging the order of the images in the album set the 1st image to 0 rank anyway?

            Thanks again Bob for the help. You truly are the Modx guru!!
              Yorkshire UK based hosting provider: https://www.simulant.uk
              • 3749
              • 24,544 Posts
              Thanks for the kind words. I'm glad that helped. smiley

              I've never actually used Gallery, so I'm afraid I'm no help on hot the ranks are set.
                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