We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37449
    • 57 Posts
    I wanted GalleryAlbums to return the count of the number of items in a gallery, so I could display this as part of the row template.

    After some reading up of the modx engine, I believe I have done what I needed.

    The code modifies the GalleryAlbum snippet as follows:

    foreach ($albums as $album) {
        $albumArray = $album->toArray();
        $c = $modx->newQuery('galItem');
        $c->innerJoin('galAlbumItem','AlbumItems');
        $c->where(array(
            'AlbumItems.album' => $album->get('id'),
        ));
        $c->sortby($albumCoverSort,$albumCoverSortDir);
        $c->limit(1);
        $coverItem = $modx->getObject('galItem',$c);
        
        /* NEW LINE - GET ITEM COUNT */
        $albumArray['albumCount'] = $modx->getCount('galItem',$c);
    
        if ($coverItem) {
            $albumArray['image'] = $coverItem->get('thumbnail',$thumbProperties);
        }
        $albumArray['cls'] = $rowCls;
        $albumArray['idx'] = $idx;
        $albumArray['showName'] = $showName;
        $albumArray['albumRequestVar'] = $albumRequestVar;
        $output[] = $gallery->getChunk($rowTpl,$albumArray);
        $idx++;
    }
    


    The highlighted line is my addition.

    Feel free to test - it works for me on my sites, and I have tested locally, on a live site, etc. - but usual caveats apply!


    If someone could point me in the right direction for submitting this as suggestion for future releases, I’ll happily file a request....
      formerly sumodaz on here!
      • 34120
      • 236 Posts
      Nice work! I’m not sure how you file a request, maybe through github?

      I always forget about little changes like this and end up losing them when I update a package.

        • 37449
        • 57 Posts
        Yes, I think it’s through github...
          formerly sumodaz on here!