Hi I have this awesome snippet (not sure now who wrote it) that pulls the first gallery album image in so when you click a page with a gallery on the first image shows. As I've added more albums and pages though it has stopped working on the latest ones. The only thing I can see is that the image IDs are over 100... Can anyone please help with a fix so first album images with ID over 100 also are now pulled in?
<?php
$path = $modx->getOption('gallery.files_url');
$album = $modx->getOption('album', $scriptProperties, false);
if (!$album) { return ''; }
if ($modx->getOption('checkForRequestVar',$scriptProperties,true)) {
$getParam = $modx->getOption('getParam',$scriptProperties,'galItem');
if (!empty($_REQUEST[$getParam])) { $id = (int)$_REQUEST[$getParam]; }
}
if ($id) { return ''; };
$sql = "SELECT item.* FROM modx_gallery_items item
INNER JOIN modx_gallery_album_items a ON item.id = a.item AND a.rank = 0
WHERE a.album = :album";
$stmt = $modx->prepare($sql);
$stmt->execute(array('album'=> $album));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$row['fullpath'] = $path . "" . $row['filename'];
$modx->toPlaceholders(array('single' => $row));
ps here is my snippet call:
[[!Gallery? &album=`[[*templatevariableforgallery]]` &toPlaceholder=`gallery`]]
[[!GalleryItem?]]
[[+galitem.image:notempty=`<div class="image">
<img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" />
</div>`]]
[[+galitem:empty=`<div class="image">
[[!getFirstImage? &album=`[[*templatevariableforgallery]]` ]]
<img src="[[+single.fullpath]]" alt="[[+single.description]]" />
</div>`]]
<div style="display: block; position: relative; overflow: hidden; margin: auto;">
[[!+gallery:notempty=`
[[+gallery]]
`]]
</div>
<p> </p>
[ed. note: jonahnaylor last edited this post 11 years ago.]
Hi can I bump this up. It seems that image IDs over 100 aren't effecting anything. Gallery first images are still showing for some resources/galleries but not others. Can anyone help please?
[ed. note: jonahnaylor last edited this post 10 years, 8 months ago.]
I don't see anything obvious unless the problem images don't have rank of 0 (take a look in the DB).
Hi Bob - thank you!
Turns out that's exactly what it was. Once I set the first image of each album to rank 0 in the database it displayed as it should.
What gives the image the rank 0 to begin with and is there a way to adjust the snippet to account for future problems with images that don't have 0 rank? Shouldn't dragging the order of the images in the album set the 1st image to 0 rank anyway?
Thanks again Bob for the help. You truly are the Modx guru!!
Thanks for the kind words. I'm glad that helped.
I've never actually used Gallery, so I'm afraid I'm no help on hot the ranks are set.