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 can anyone help with a Gallery modx snippet that pulls in the first image of the gallery.

    It was working great but now no image appears when the page loads.

    The gallery call code is:

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


    and the getFirstImage snippet is:

    <?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));



    Thanks if anyone can please help to get this working again...
      Yorkshire UK based hosting provider: https://www.simulant.uk