How is it possible to group albums by year?
For example:
2014
- Album 1
- Album 2
2013
- Album 3
I've recently seen that it is possible to group them in the backend using a subfolder-like approach to sort them - but is it also possible to query albums for a specific folder?
I'm currently using this call in my Gallery overview:
[[!GalleryAlbums? &sort=`year` &albumCoverSort=`random` &rowTpl=`galAlbumRowTpl`
&toPlaceholder=`galleries` &showAll=`1` &parent=`6`
&prominentOnly=`0` &limit=`50`]]
<div class="galleries">[[+galleries]]</div>
Currently the GalleryAlbums Snippet doesn't support sorting by year, even though there's a "year" field for the Album object:
However, there's a couple ways to do this.
1. Write your own Snippet
This would be the most performant option, but instructions for this might be out of scope here, so another option might be:
2. Nested Template Chunks
Organize your albums by nesting them under parent albums named after the year. So you'd have an album called "2014" and under that you'd have child albums you want to display for that year.
Then modify your snippet call to include these properties:
&showAll=`0`
&parent=`0`
According to the Gallery documentation, this is what those properties do:
showAll If 1, will show all albums regardless of their parent.
parent Grab only the albums with a parent album with this ID. Remember to set showAll to 0, otherwise it won't work!
Now modify your rowTpl, so that it's something like this:
<li>[[+name]]
<ul>[[GalleryAlbums? &showAll=`0` &parent=`[[+id]]` ... ]]</ul>
</li>
What this means, is that your "outer" Snippet call gets only "top-level" albums, because you specified that the parent attribute must be "0". Then the tpl for each album calls the Gallery snippet again, with the parent property as the ID of the currently iterated Album, thereby returning a list of child Albums. Note in the above code sample, I've omitted the other important properties like &rowTpl, which you would need to populate.
NOTE: I see you're calling your Snippet with the uncached token !
. You might get performance gains by caching it, especially if you use an aggressive caching mechanism like StatCache. Granted the GalleryAlbums getList processor utilizes its own cache handler, but there will likely be performance penalties for using a nested Snippet call like the one I've described here.