How to display ALL album images using Gallery extra?

Is there a way to show all images from all albums using the Gallery extra?
Thanks for any help

You want all images from each album in each page or from all albums at once?

I haven’t used the Gallery extra in a long time and I haven’t tested this but you could make a snippet containing something like this:

<?php
$gallery = $modx->getService(
    'gallery',
    'Gallery',
    $modx->getOption('gallery.core_path', null, $modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties
);
if (!($gallery instanceof Gallery)) return '';

$images = $gallery->modx->getCollection('galItem');
$output = '';
foreach($images as $image) {
    $imageArray = $image->toArray();
    $output .= $modx->getChunk('yourChunkTplName',$imageArray);
}
return $output;

Yes that’s right. I’m trying to get it to work with the isoptope filter
Thanks for the snippet but i can’t seemn to get it to work unless i’m doing something wrong.

Did you change the chunk name to the one you’re using?
any errors in the log?

Sorry for the forgotten topic, but could you please help with the same task.

digitalpenguin, It seems that your snippet is working, but can I have some questions:

  1. What is the simplest way to limit and sort photos?
  2. How to specify correct URLs (placeholders) to images?

My chunk is:

<div class="photo-tpl col-md-3 col-6">
<a data-fancybox="gallery" rel="gallery" class="fancybox" data-caption="[[+name]]" href="[[+image_absolute:pthumb=`w=1280&h=720&zc=1`]]" title="[[+name]]" [[+link_attributes]] >
	<img src="[[+image_absolute:pthumb=`w=416&h=300&zc=1`]]" alt="[[+name]]" />
</a>
</div>

Images a not loading at SRC path, shown only ALT attribute. I’ve tried [[+image]], it didn’t help. But in native “[[!Gallery?]]” snippet photos are displayed OK.

Thanks beforehand for help.

P.S. Or maybe you can advice - how to show only images from some albums (including nested), sorting by date and limit by quantity.

You have to create a “xPDOQuery”. Then call the sortby and limit functions. Use this query in the call to “getCollection()”

...
$q = $modx->newQuery('galItem');
$q->sortby('createdon','DESC');
$q->limit(5);

$images = $gallery->modx->getCollection('galItem', $q);
...

There is no “image_absolute” placeholder in the snippet above. So you have to add that yourself.
Maybe something like this works for you:

...
$filesUrl = $modx->call('galAlbum','getFilesUrl',array(&$modx)); //NEW
foreach($images as $image) {
    $imageArray = $image->toArray();
    $imageArray['image_absolute'] = $filesUrl . $image->get('filename'); //NEW
    $output .= $modx->getChunk('yourChunkTplName',$imageArray);
}
...
1 Like

Thank you! It’s working OK!