Forum

Thread tagged as: Question, Gallery

How to get the album image

OK, so how do I grab the album image here? I have just put $album['albumImage'] but that is clearly not right.

<?php
$albums = perch_gallery_album_listing([
        'image'=>true,
        'skip-template' => true,
         ]); 
?>
<ul>
<?php 
    foreach ($albums as $album) {
    echo '<li><a href="?s='.$album['albumSlug'].'"<img src="'.$album['albumImage'].'" /></a><a href="?s='.$album['albumSlug'].'"><h2>'.$album['albumTitle'].'</h2></a></li>';   
    }
?></ul>

Ultimately I want to be able to check if the current slug matches the album slug and to add a class to the image, but I have got stuck even adding the image so far!

Lisa Morena

Lisa Morena 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does this give you?

print_r($album);

Sorry, I didn't get email notification of your reply.

Array ( [albumimage] => Array ( [assetID] => 7 [title] => Chairs [_default] => /my_cms/resources/chairs-1.jpg [bucket] => default [path] => chairs-1.jpg [size] => 15195 [w] => 227 [h] => 170 [mime] => image/jpeg [sizes] => Array ( [thumb] => Array ( [w] => 150 [h] => 112 [target_w] => 150 [target_h] => 150 [density] => 2 [path] => chairs-1-thumb@2x.jpg [size] => 12926 [mime] => [assetID] => 8 ) [w170h170c1] => Array ( [w] => 170 [h] => 170 [target_w] => 170 [target_h] => 170 [crop] => true [density] => 1 [path] => chairs-1-w170h170.jpg [size] => 8142 [mime] => image/jpeg ) ) ) [albumID] => 1 [albumTitle] => Chairs [albumSlug] => chairs [albumOrder] => 1 [albumDynamicFields] => {"albumimage":{"assetID":"7","title":"Chairs","_default":"\/my_cms\/resources\/chairs-1.jpg","bucket":"default","path":"chairs-1.jpg","size":15195,"w":227,"h":170,"mime":"image\/jpeg","sizes":{"thumb":{"w":"150","h":"112","target_w":150,"target_h":150,"density":2,"path":"chairs-1-thumb@2x.jpg","size":12926,"mime":"","assetID":"8"},"w170h170c1":{"w":170,"h":170,"target_w":"170","target_h":"170","crop":"true","density":"1","path":"chairs-1-w170h170.jpg","size":8142,"mime":"image\/jpeg"}}}} [imageCount] => 3 [perch_albumimage] => Array ( [assetID] => 7 [title] => Chairs [_default] => /my_cms/resources/chairs-1.jpg [bucket] => default [path] => chairs-1.jpg [size] => 15195 [w] => 227 [h] => 170 [mime] => image/jpeg [sizes] => Array ( [thumb] => Array ( [w] => 150 [h] => 112 [target_w] => 150 [target_h] => 150 [density] => 2 [path] => chairs-1-thumb@2x.jpg [size] => 12926 [mime] => [assetID] => 8 ) [w170h170c1] => Array ( [w] => 170 [h] => 170 [target_w] => 170 [target_h] => 170 [crop] => true [density] => 1 [path] => chairs-1-w170h170.jpg [size] => 8142 [mime] => image/jpeg ) ) ) ) 
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you replace

$album['albumImage']

with

$album['albumImage']['_default']

what does that get you?

Nothing :(

oohhh, this works though:

$album['perch_albumimage']['_default']

OK, so how can I pull the resized image rather than the original one then?

Aha! Got it!

$album['perch_albumimage']['sizes']['w170h170c1']['path']