Thread tagged as: Question

Filtering Gallery by related field

Hi Guys,

I am trying to setup a page that filters a gallery based on a related field, based on a slug of the page. When I do a showall I get the following;

url_0   /artists/catherine-t
url_artist  catherine-t
url_1   catherine-t
perch_page_path /artists
domain  //localhost:8080
url //localhost:8080/artists/catherine-t/
albumID 1
albumTitle  Supershoes
albumSlug   supershoes
albumOrder  1
albumDynamicFields  {"description":{"_flang":"textile","raw":"","processed":""}}
imageCount  2
pair_number 1
_title  1
    [0] => 2
    [0] => 39
imageID 1
imageAlt    Super Kendal
imageSlug   02-superkendal
imageOrder  1
imageDynamicFields  {"pair_number":"1","_title":"1","artist":["2"],"sponsor":["39"]}
imageStatus active
imageBucket default
perch_pair_number   1
perch__title    1
    [0] => 2
    [0] => 39
full    /cms/resources/02-superkendal-w1200h900.jpg
full-w  1200
full-h  800
full-id 1
full-key    full
thumb   /cms/resources/02-superkendal-w150h150.jpg
thumb-w 150
thumb-h 150
thumb-id    2
thumb-key   thumb
thumb_2x    /cms/resources/02-superkendal-w300h300.jpg
thumb_2x-w  300
thumb_2x-h  300
thumb_2x-id 3
thumb_2x-key    thumb_2x
original    /cms/resources/02-superkendal.jpg
original-w  3888
original-h  2592
original-id 4
original-key    original
admin_thumb /cms/resources/02-superkendal-w80h80.jpg
admin_thumb-w   80
admin_thumb-h   80
admin_thumb-id  5
admin_thumb-key admin_thumb
admin_preview   /cms/resources/02-superkendal-w180.jpg
admin_preview-w 180
admin_preview-h 120
admin_preview-id    6
admin_preview-key   admin_preview
_id 1
perch_item_first    true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    2
perch_item_rev_zero_index   1
perch_item_count    2
perch_namespace perch:gallery

I am trying to filter on the perch_artist section as this is the related field where you choose the artist for that gallery item.
The page is displayed based on the artists slug. E.G /artists/catherine-t/

I can do this with perch_content_custom and works nicely like so;

perch_content_custom('Stories', array(
                'page'          => '/stories',
                'template'      => 'stories/_teaser',
                'filter'        => 'artist.artist_slug',
                'match'         => 'eq',
                'value'         => perch_get('artist'),

But how can I do this with the Galleries? I have tried this....

perch_gallery_album_images('supershoes', array(
                'template'      => 'a_list_image',
                'filter'        => 'artist.artist_slug',
                'match'         => 'eq',
                'value'         => perch_get('artist'),

Thanks, Terry

Terry Upton

Terry Upton 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us your template?


image.html template;

<perch:gallery id="image" type="image" key="full"  width="1200" height="900" bucket="gallery" />
<perch:gallery id="image" type="image" key="thumb" width="150" height="150" crop="true" bucket="gallery" />
<perch:gallery id="image" type="image" key="thumb_2x" width="300" height="300" crop="true" bucket="gallery" />

<perch:gallery id="pair_number" type="text" label="Pair Number" required="true" title="true" help="This is the number for this particular pair of Supershoes" />

<perch:related id="artist" collection="artists" label="Super Artist">
    <perch:gallery id="artist_firstname" type="text" /> <perch:gallery id="artist_surname" type="text" chars="1" format="UC" />

<perch:related id="sponsor" collection="sponsors" label="Super Sponsor">
    <perch:gallery id="sponsor_name" type="text" />

and the a_list_image.html template

    <ul class="gallery // gallery--full // gallery--supershoes // mixitup">
    <li class="mix // gallery--full__item // <perch:related id="artist" collection="artists"><perch:gallery id="artist_slug" /></perch:related> // <perch:related id="sponsor" collection="sponsors" /><perch:gallery id="sponsor_slug" type="text" /></perch:related>" data-myorder="<perch:gallery id="imageOrder" />">
        <a href="<perch:gallery id="full"  />" data-sponsor="Sponsor: <perch:related id="sponsor" collection="sponsors" label="Super Sponsor"><perch:gallery id="sponsor_name" type="text" /></perch:related>" data-artist="Artist:  <perch:related id="artist" collection="artists" label="Super Artist"><perch:gallery id="artist_firstname" type="text" /> <perch:gallery id="artist_surname" type="text" chars="1" format="UC" /></perch:related>">
            <img src="<perch:gallery id="thumb" />"
            srcset="<perch:gallery id="thumb" /> 1x, <perch:gallery id="thumb_2x" /> 2x"

            alt="(Supershoes Pair #<perch:gallery id="pair_number" type="text" />) - <perch:gallery id="imageAlt" type="text" />"

            class="img-circle // img-border"
Drew McLellan

Drew McLellan 2638 points
Perch Support

I suspect this may not work with the Gallery app due to its vintage.

Would you recommend another approach then? Collection or List/Details page perhaps?
Or can I do something with the gallery app but a little more manual PHP code?

Any thoughts on this Drew?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sorry, it's been the weekend.

I'm not sure I can really make a recommendation, as I don't know your aims and objectives. We can help if you hit problems with the software, but how you structure the site is really your call.

Thanks Drew. I understand what you are saying. I guess what I was getting at is it likely that the gallery would be extended to include this functionality. Or now we have runway/collections etc, do you guys see the gallery as a redundant/dead app that will unlikely undergo any further development. So in that case based on the direction Perch are moving in, would it be of your opinion to approach it differently and not use the gallery app.

In this instance, my aim is to pull all related images from a gallery into a particular artists page. This page also pulls in related stories from a list/details page too (which works nicely).

Drew McLellan

Drew McLellan 2638 points
Perch Support

The plan is that Gallery will be deprecated and the functionality rolled directly into Assets.

Thanks Drew. I have decided to change this into a Collection. All functioning as it should now.