What I would like to do is create a snippet that gets the first image of every gallery

)<div class="whatever"> <div class="image">[[MaxiGallery? &gal_query_ids=`[+id+]` &limit=`1`]]</div> <div class="info">[+yourtvname+]</div> </div>
<?php
/* parameters:
* &tpl - chunk for formatting the output
* &coverField - maxigallery-customField, if isset only pics with 'on' are displayed
* &documents - if isset, only pictures of these galleries are displayed
* &parents - if isset, only pictures from childgalleries of parents are displayed
* &depth - depth from parents
* &galLimit - limits pictures for each gallery
* &random - gets a random images for each gallery
*
* call-example:
* [!maxiviewer? &tpl=`myViewerTpl`&coverField=`cover`&documents=`45,46,47`!]
* [!maxiviewer? &tpl=`myViewerTpl`&parents=`[*id*]`&galLimit=`1`&random=`1`!]
*
* chunk-examples:
* <a href="[~[+gal_id+]~]">
* <img src="[+path_to_gal+]thumb_[+filename+]"/>
* </a>
*
* <img alt="[+pagetitle+]" src="[+path_to_gal+][+filename+]" width="[+picture_width_normal+]" height="[+picture_height_normal+]"/>
*
*/
$output = '';
if ( isset ($tpl))
{
$depth = isset ($depth)?$depth:'1';
$coverwhere = isset ($coverField)?'mg.'.$coverField.' = "on"':'1';
if ( isset ($parents))
{
$parents = explode(',', $parents);
$ids = array ();
foreach ($parents as $parent)
{
$ids = $modx->getChildIds($parent, $depth, $ids);
}
if (count($ids) > 0)
{
$documents = implode(',', $ids);
}
}
$query = '
select sc.pagetitle, mg.* from '.$modx->getFullTablename('site_content').' sc
join '.$modx->getFullTablename('maxigallery').' mg on mg.gal_id = sc.id
where '.$coverwhere;
$galorder='menuindex';
$picorder=isset ($random)?' rand()':' mg.pos';
$limit= isset($galLimit)? ' LIMIT '.$galLimit:'';
if ( isset ($documents))
{
$rs = $modx->db->select('id as docid,pagetitle', $modx->getFullTablename('site_content'), 'id IN ('.$documents.')',$galorder);
$docs = $modx->db->makeArray($rs);
if (count($docs) > 0)
{
foreach ($docs as $doc)
{
$rs = $modx->db->query($query.' AND sc.id = '.$doc['docid'].' order by '.$picorder.$limit);
$docpics = $modx->db->makeArray($rs);
if (count($docpics)>0){
foreach ($docpics as $docpic){
$pics[] = $docpic;
}
}
}
}
}
elseif (!isset($parents))
{
$rs = $modx->db->query($query.' order by sc.'.$galorder);
$pics = $modx->db->makeArray($rs);
}
if (count($pics) > 0)
{
foreach ($pics as $pic)
{
$pic['path_to_gal'] = 'assets/galleries/'.$pic['gal_id'].'/';
if (file_exists($modx->config['base_path'].$pic['path_to_gal'].$pic['filename']))
{
$imagesize = getimagesize($modx->config['base_path'].$pic['path_to_gal'].$pic['filename']);
$pic['picture_height_normal'] = $imagesize[1];
$pic['picture_width_normal'] = $imagesize[0];
$pic['active'] = $pic['gal_id'] == $modx->documentObject['id']?'active':'';
}
$output .= $modx->parseChunk($tpl, $pic, '[+', '+]');
}
}
}
return $output;
?>
