Here is some code to create breadcrumbs for your album tree. It’s based on the snippet “GalleryAlbums”.
Create a snippet GalleryCrumbs
<?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 '';
/* setup default properties */
$rowTpl = $modx->getOption('rowTpl',$scriptProperties,'galAlbumRowTpl');
$rowCls = $modx->getOption('rowCls',$scriptProperties,'');
$toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
$showName = $modx->getOption('showName',$scriptProperties,true);
$scriptProperties['showAll'] = true;
$scriptProperties['prominentOnly'] = false;
$scriptProperties['checkForRequestAlbumVar'] = false;
$scriptProperties['limit'] = 0;
$scriptProperties['start'] = 0;
/* query all active albums */
$albums = $modx->call('galAlbum','getList',array(&$modx,$scriptProperties));
/* read id of current album from $_REQUEST */
$albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
$current_album = 0;
if (isset($_REQUEST[$albumRequestVar]) && !empty($_REQUEST[$albumRequestVar])){
$current_album = intval($_REQUEST[$albumRequestVar]);
}
/* iterate */
$output = array();
$albums_lookup = array();
foreach ($albums as $album) {
$albumArray = $album->toArray();
$albums_lookup[$albumArray['id']] = $albumArray;
}
$root_reached = false;
$search_id = $current_album;
while (!$root_reached) {
$found = false;
if (array_key_exists($search_id, $albums_lookup)) {
$albumArray = $albums_lookup[$search_id];
$classes = array($rowCls);
if ($current_album == $albumArray['id']) {
$classes[] = 'gallery-crumb-current';
}
$albumArray['cls'] = implode(' ', $classes);
$albumArray['showName'] = $showName;
$albumArray['albumRequestVar'] = $albumRequestVar;
$output[] = $gallery->getChunk($rowTpl,$albumArray);
$found = true;
$search_id = $albumArray['parent'];
}
if (!$found || $search_id == 0){
$root_reached = true;
}
}
/* Show a 'Home' Crumb */
$showHomeCrumb = $modx->getOption('showHomeCrumb',$scriptProperties,true);
$homeCrumbTpl = $modx->getOption('homeCrumbTpl',$scriptProperties,'');
if ($showHomeCrumb && $homeCrumbTpl){
$albumArray = array();
$classes = array($rowCls);
$classes[] = 'gallery-crumb-home';
$albumArray['cls'] = implode(' ', $classes);
$output[] = $gallery->getChunk($homeCrumbTpl,$albumArray);
}
$output = array_reverse($output);
/* set output to placeholder or return */
$outputSeparator = $modx->getOption('outputSeparator',$scriptProperties," > ");
$output = implode($outputSeparator,$output);
if ($toPlaceholder) {
$modx->setPlaceholder($toPlaceholder,$output);
return '';
}
return $output;
then call it (uncached) with
[[!GalleryCrumbs]]
or
[[!GalleryCrumbs?
&showHomeCrumb=`1`
&homeCrumbTpl=`galHomeCrumbTpl`
&rowTpl=`galCrumbTpl`
&rowCls=`my-crumb-class`
&outputSeparator=` - `
]]
Chunk galHomeCrumbTpl
<span[[+cls:notempty=` class="[[+cls]]"`]]><a href="[[~[[*id]]]]">All albums</a></span>
Chunk galCrumbTpl
<span[[+cls:notempty=` class="[[+cls]]"`]]><a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]">[[+showName:notempty=`[[+name]]`]]</a></span>
This code isn’t thoroughly tested and probably contains some bugs.