Sean Kimball
Sean Kimball

Reputation: 4494

How do I get a galleries cover image in modx revolution?

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

Answers (2)

Ronald Aus der Au
Ronald Aus der Au

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:

  1. Create a Template Variable called gallery_album with the input type galleryalbumlist.
  2. Make it accessible to your preferred template.
  3. Open up, or create a resource with that template. The Template Variable will be in the Template Variable Tab as a Dropdown containing all the previously created albums.
  4. Choose an album from the dropdownlist
  5. when you know call [[+gallery_album]] in the template, it will output the Album-ID

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

Sean Kimball
Sean Kimball

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

Related Questions