Sort Gallery image

I have many albums in the modx gallery. I need images in albums created after June 2023 to be sorted by name, and the rest by id (rank). All my attempts to make the condition ended in failure. What am I doing wrong? Thanks in advance kind people. I am attaching the chunk code.

[[!Gallery? &thumbWidth=`200` &thumbHeight=`150` &thumbZoomCrop=`1` &imageWidth=`1024` &imageHeight=`768` &thumbTpl=`newGalThumb` &sort=[[+publishedon:strtotime:06-2023]] >= [[+publishedon:strtotime:06-2023]] ? 'name' : 'rank' ]]

In other words, I need the new images of the new albums to be sorted by the new sort, and the old ones by the old sorting.

What exactly is the [[+publishedon]] placeholder? Where does it get set and what is the value?


My guess is, that you have to write a custom snippet that returns the correct sort field based on the request parameter for the album (usually galAlbum).

You could query the correct album from the database and determine the sort field based on the createdon field of the album. But it’s probably easier to check which is the lowest album-ID for an album created after June 2023, and then return “name” for all IDs that are higher (and “rank” for all IDs that are lower).