Reputation: 4494
How do I get a galleries cover image in modx revolution?
Currently I'm calling the gallery by ID and limiting it to one image ~ however, this does not garantee that the image will be the cover image.
this is what I am currently doing.
[[!Gallery? &album=`[[!+tv.vehiclegallery]]` &toPlaceholder=`gallery` &thumbTpl=`homepageVehicleThumbTpl` &limit=`1`]]
[[+gallery]]
Upvotes: 0
Views: 1423
Reputation: 21
The answer is way more simple! I was looking at this for hours and couldnt figure it out, then it hit me. The cover of every album is always called "cover.jpg". And it will be stored in the assets folder with the corresponding Album-ID.
Path abstract:
assets/gallery/[album-id]/cover.jpg
For example:
assets/gallery/1/cover.jpg
So as long as you have the Album-ID you can get the cover.
Getting the Album-ID
If you want the Album-ID heres one way:
Code example: <img src="assets/gallery/[[+gallery_album]]/cover.jpg"
Link to the modx extra Gallery:
https://docs.modx.com/current/en/extras/gallery/gallery/index
Upvotes: 2
Reputation: 4494
I would up doing this in a snippet instead:
<?php
//getgalleryAlbumCover
$output = '';
$sql = "select * from modx_gallery_albums mga where mga.id = $id";
$album = $modx->query($sql);
if (!is_object($album)) {return;}
$data = $album->fetch(PDO::FETCH_ASSOC);
// just in case ;)
$modx->toPlaceholders($data);
$output = $data['cover_filename'];
return $output;
Upvotes: 0