-
☆ A M B ☆
- 894 Posts
Just add the id parameter to your GalleryItem call like this:
[[!GalleryItem? &imageWidth=`260` &id=`1`]]
That should always load the first image when you load the page.
Good Luck.
Sorry, don't know how i missed that in the documentation!!! If the default photo is not always going to be 1 however is there anyway for it to pick the next available image. For example, if you delete the image with id=1 from a gallery and it no longer exists, i don't want to have to update the &id property in galleryitem. Any ideas?
-
☆ A M B ☆
- 894 Posts
Not that I know of, sorry.
Quote from: benmarte at Oct 09, 2013, 12:30 PMJust add the id parameter to your GalleryItem call like this:
[[!GalleryItem? &imageWidth=`260` &id=`1`]]
That should always load the first image when you load the page.
Good Luck.
Hi I'm also trying to load up the first image but I can't get it to work. Here is my code:
[[!Gallery? &album=`[[*property-gallery]]` &toPlaceholder=`gallery`]]
[[!GalleryItem? &id=`1`]]
[[!+galitem.image:notempty=`
<div class="image">
<img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+galitem.name]]" />
</div>
`]]
<div style="display: block; position: relative; overflow: hidden; margin: auto;">
[[!+gallery:notempty=`
[[+gallery]]
`]]
</div>
Any ideas how I can get this working? Thanks for any help.
Did anyone ever figure this out? I too, would like to be able to return the first item in each gallery. So if I have 2 galleries, and each have 5 pictures, the first gallery would return "1" as the default image, and the second gallery would return "6" as the first image in that gallery. I've searched and searched, and can't seem to find anything about it.
Hi this snippet works:
<?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));
Which is then included in your Gallery call like this:
[[!Gallery? &album=`[[*gallerytemplatevariable]]` &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=`[[*gallerytemplatevariable]]` ]]
<img src="[[+single.fullpath]]" alt="[[+single.description]]" />
</div>`]]
<div style="display: block; position: relative; overflow: hidden; margin: auto;">
[[!+gallery:notempty=`
[[+gallery]]
`]]
</div>
BUT I'm also having a problem with this. Once the gallery album IDs get over 100 it doesn't seem to work... I'm not sure why. Can anyone please help at all?
Thanks.