Forum

Thread tagged as: Gallery

Using multiple filters for perch_gallery_albums()

I'm on the latest version of Perch and the Gallery add-on.

I need to use multiple filters for the album listing. This is what I have so far:

perch_gallery_albums(array(
    'template' => 'album-listing.html',
    'image' => true,
    'filter' => 'excludeWeb',
    'match' => 'neq',
    'value' => 'excludeWeb'
)); 

And it works perfectly. But when I change it to the following, the filter doesn't work anymore, and it's showing all albums:

perch_gallery_albums(array(
    'template' => 'album-listing.html',
    'image' => true,
    'filter' => array(
        array(
            'filter' => 'excludeWeb',
            'match' => 'eq',
            'value' => 'excludeWeb'
        )
    )
));

Are multiple filters not possible for this function, or am I doing something wrong?

Thanks!

Louis Bataillard

Louis Bataillard 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The Gallery app predates multiple filters - you can only use one.

Thanks for the heads-up. Can you think of any workaround? We have two different types of albums and need to display two separate lists.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What other factor do you need to filter on?

Ah, sorry.

The other factor would be "Exclude from Web". We have different channels for the galleries (website and mobile app), and some need to be displayed on the mobile app only.

So the filters are:

  • Exclude from web
  • Gallery type
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think the workaround would be to filter the "exclude from web" attribute within the template.

This works, but then I'm having a problem with the "perch:every" tag, as the "exclude from web" items are still counted as children but are not displayed, messing up my row alignment. Have a look at the following (simplified) example:

<perch:if exists="excludeWeb">
    <!-- Don't output this item -->
<perch:else />
    <perch:every nth-child="4n+1">
        <!-- Start a new row for every 5th item -->
        <div class="row">
    </perch:every>
    <!-- Code for the item follows here... -->
</perch:if>

For example if the 4th item is an "exclude from web" item it won't be displayed, but the 5th item will be displayed in a new row, leaving the preceding row with only 3 items (since the 4th one is an "exclude from web" item), messing up the grid display.

Any ideas for a fix?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't think of a way around that.