Forum
Gallery album filtering
Is there a way to filter albums on a page? I'm trying to filter the albums on this page the bottom part, the smaller sets of images.
The page only needs to show the albums which are ‘Projecten’ albums. At the moment all of these are ‘statically’ generated like this :
<?php perch_gallery_album('project-1', array(
'template'=>'my_album-projecten.html'
)); ?>
<?php perch_gallery_album(‘project-2', array(
'template'=>'my_album-projecten.html'
)); ?>
<?php perch_gallery_album(‘project-3', array(
'template'=>'my_album-projecten.html'
)); ?>
Since I regularly have to be abel to update this it’s a hassle each time. It should be dynamic, as sometimes I need to delete one, add one, update one etc. I tried this but this doesn’t work (nothing gets outputted):
<?php perch_gallery_build(array(
'filter'=>'category',
'match'=>'eq',
'value'=>'Projecten',
'template'=>'my_album-projecten.html'
)); ?>
When I try this :
<?php perch_gallery_build(array(
'template'=>'my_album-projecten.html'
)); ?>
All my albums are displayed on the page. I figured since I have this dropdown there - see dropdown 'Projecten' in this screenshot: I assume I can use that dropdown field as a filter parameter? Or is there another way for me to filter these so I can make this whole part dynamic?
Thank you for the help.
You can use
perch_gallery_albums()
to dynamically get your albums, and filter that by the field from your template.This will list all the albums where the field with the template
id
ofmy_id
has a value ofProjecten
.https://docs.grabaperch.com/functions/gallery/perch-gallery-albums/
Hi Drew,
Thank you for the help. If I try this :
or this:
nothing gets output.
This is my 'album.html' template code:
As you can see the id of the field is 'category'. Hope you know what i'm still doing wrong. Thanks again.
Ok, that looks fine. What is your code for
my_album-projecten.html
?You can try adding a
<perch:showall />
tag to that template to see what content is being made available to it.This is the code:
Ah, ok. I think this is what you need in your page to make the album listing dynamic:
Thank you. I pasted this code:
It's just I don't know PHP. I assume I need to add the beginning and ending tags here. I still have no luck with this code. I'm currently trying this out on this test page. It's weird it's still not outputting the content.
If you View Source you can see the content just terminates, which means you have a PHP error.
What does your entire page look like, and does this page include the Perch runtime?
Here is the code of the complete page:
It's a copy (test.php) of the one that is currently online here but then with the code part of the small images (below big visuals at the top) edited with the 'new' code.
Can I see your Diagnostics Report?
Here it is:
It looks like you're on a really old version of the Gallery app. Can you try switching:
for
If that helps then it's just that your Gallery is out of date and should be updated to the newest one.
Hi Drew,
I've adjusted it to 'perch_gallery_album_listing' and now the content loads fine. So that seemed to be the problem. I wasn't aware when I did the Perch update that the Gallery app needs separate updating too. I'll have a look to update it asap. Then I'll try the 'new' code instead so it's all up-to-date again.
Thanks to you both, Veerle
Just FYI updated the Gallery app and everything seems to work fine. Thank you again.
If you update Perch it's generally a good plan to update the add-ons too. We have more information in the Control Panel about add-ons for Perch 3 which should make that easier.