Forum

Thread tagged as: Problem

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.

Veerle Pieters

Veerle Pieters 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch_gallery_albums() to dynamically get your albums, and filter that by the field from your template.

perch_gallery_albums([
     'filter' => 'my_id',
     'value' => 'Projecten',
]);

This will list all the albums where the field with the template id of my_id has a value of Projecten.

https://docs.grabaperch.com/functions/gallery/perch-gallery-albums/

Hi Drew,

Thank you for the help. If I try this :

<?php perch_gallery_albums(array( 
                        'template'=>'my_album-projecten.html',
                        'filter' => 'category', 
                        'value' => 'Projecten', 
                        )); ?>

or this:

<?php perch_gallery_albums([
                        'template'=>'my_album-projecten.html',
                        'filter' => 'category', 
                        'value' => 'Projecten', 
                        ]); ?>

nothing gets output.

This is my 'album.html' template code:

<h2><perch:gallery id="albumTitle" type="text" label="Title" size="l" /></h2>
<perch:gallery id="description" type="textarea" label="Description" editor="markitup" textile="true" order="1" size="m" />
<perch:gallery id="category" type="select" options="Projecten, Projectenslider,Tuinaanleg, In De Kijker, Demotuin, Homepage" />
<perch:gallery id="image" type="image" key="small" width="284" height="159" crop="true" />

As you can see the id of the field is 'category'. Hope you know what i'm still doing wrong. Thanks again.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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:

<perch:before>
<div class="one unit">
    <section class="photo-stack">   
        <div><div>
</perch:before> 
            <figure<perch:if id="perch_item_index" match="gte" value="2"> class="hidden"</perch:if>>
                <a href="<perch:gallery id="main" />" class="fancybox" rel="<perch:gallery id="albumSlug" />" title="<perch:gallery id="albumTitle" type="text" label="Title" size="l" />"><img src="<perch:gallery id="small" />" width="284" height="159" /></a>
                <figcaption><perch:gallery id="albumTitle" type="text" label="Title" size="l" /></figcaption>
                <strong><span><perch:gallery id="imageCount" /></strong></span>
            </figure>
<perch:after>           
        </div></div>
    </section>
</div>
</perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, ok. I think this is what you need in your page to make the album listing dynamic:

// get the albums
$albums = perch_gallery_albums([ 
    'filter' => 'category',  
    'value' => 'Projecten',  
    'skip-template' => true,
]);

// loop through the albums
foreach($albums as $album) {
    perch_gallery_album($album['albumSlug'], [
        'template'=>'my_album-projecten.html'  
    ]);
}

Thank you. I pasted this code:

<?php 
                    // get the albums
                    $albums = perch_gallery_albums([  
                    'filter' => 'category',  
                    'value' => 'Projecten',  
                    'skip-template' => true, 
                    ]);  
                    // loop through the albums
                    foreach($albums as $album) { 
                        perch_gallery_album($album['albumSlug'], [ 
                        'template'=>'my_album-projecten.html'  
            ]);
                } ?>

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.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

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:

<?php include('../perch/runtime.php'); ?>
<?php perch_layout('global.header', array(
    'title'=>'Projecten',
    'class'=>'projecten',
)); ?>

            <div role="main">

                <h2 class="page-header">Projecten</h2>

                <?php perch_content('Projecten'); ?>


                <div class="grid row">

                    <section class="slider">
                        <!--https://designmodo.com/responsive-slider/-->

                        <div class="flex-container">
                            <div class="flexslider">
                                <ul class="slides">
                                    <?php perch_gallery_album('projecten-slider-beelden', array(
                                       'template'=>'my_album-slider.html' 
                                    )); ?>
                                </ul>
                            </div>
                        </div>

                    </section>

                </div><!-- //grid row-->

                <div class="grid row">
                    <?php 
                    // get the albums
                    $albums = perch_gallery_albums([  
                    'filter' => 'category',  
                    'value' => 'Projecten',  
                    'skip-template' => true, 
                    ]);  
                    // loop through the albums
                    foreach($albums as $album) { 
                        perch_gallery_album($album['albumSlug'], [ 
                        'template'=>'my_album-projecten.html'  
            ]);
                } ?>

                </div><!-- //grid row-->

            </div>

            <hr />

        </div><!-- //container-->

    </div><!-- //wrapper -->

    <?php perch_layout('global.footer'); ?>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="/js/libs/jquery-1.9.0.min.js"><\/script>')</script>

        <script src="/js/libs/jquery.flexslider-min.js"></script>
        <script src="/js/libs/jquery.mousewheel-3.0.6.pack.js"></script>
        <script src="/js/jquery.magnific-popup.js"></script>
    <script>
        $(document).ready(function() {
            $('figure').magnificPopup({ 
              delegate: 'a',
                    type: 'image',
                    tLoading: 'Loading image #%curr%...',
                    mainClass: 'mfp-img-mobile',
                    gallery: {
                        enabled: true,
                        navigateByImgClick: true,
                        preload: [0,1] // Will preload 0 - before current, and 1 after the current image
                    },
                    image: {
                        tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
                    }
            });
        });     
        </script>
        <script>
            $(document).ready(function() {
                $('.flexslider').flexslider({
                    animation: 'fade',
                    controlsContainer: '.flexslider'
                });
            });
        </script>
        </body>
</html>

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.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can I see your Diagnostics Report?

Here it is:

PERCH INFORMATION

Perch: 2.8.34
Production mode: Production (100)
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), perch_forms (1.5), perch_gallery (2.7)
DB driver: PDO
DB tables: perch2_categories (0), perch2_category_counts (0), perch2_category_sets (0), perch2_content_index (361), perch2_content_items (341), perch2_content_regions (11), perch2_forms (1), perch2_forms_responses (71), perch2_gallery_albums (28), perch2_gallery_image_versions (2001), perch2_gallery_images (263), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (1), perch2_pages (11), perch2_resource_log (598), perch2_resource_tags (0), perch2_resources (130), perch2_resources_to_tags (0), perch2_settings (17), perch2_user_passwords (0), perch2_user_privileges (33), perch2_user_role_privileges (19), perch2_user_roles (2), perch2_users (2)
Users: 2
PHPMailer: 5.2.21
App runtimes:
<?php
    include(PERCH_PATH.'/core/apps/content/runtime.php');
    include(PERCH_PATH.'/addons/apps/perch_gallery/runtime.php');
    include(PERCH_PATH.'/addons/apps/perch_forms/runtime.php');
?>
Editor plug-ins: markitup
H1: 318964e49637ddaf677a18620913999e
L1: 32189b3999922300b7ccc1920577f253
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
headerColour: #f9f9f9
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.2.3: done
latest_version: 2.8.15
headerScheme: light
dashboard: 0
content_hideNonEditableRegions: 0
logoPath: /perch/resources/1367841198_logo.png
update_2.2.5: done
perch_gallery_update: 2.7
on_sale_version: 2.8.34
update_2.8.34: done
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: dekorenb_db
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: dekorenb_db
PERCH_DB_PREFIX: perch2_
PERCH_TZ: Europe/Brussels
PERCH_EMAIL_FROM: veerle@duoh.com
PERCH_EMAIL_FROM_NAME: Veerle Pieters
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/dekorenbloemcom/public_html/perch
PERCH_CORE: /home/dekorenbloemcom/public_html/perch/core
PERCH_RESFILEPATH: /home/dekorenbloemcom/public_html/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /home/dekorenbloemcom/public_html/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
HOSTING SETTINGS

PHP: 5.6.20
Zend: 2.6.0
OS: Linux
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
MySQL server: 5.5.5-10.0.29-MariaDB
Free disk space: 112.26 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, calendar, ctype, curl, dom, filter, ftp, gd, gettext, hash, iconv, SPL, json, mbstring, mcrypt, session, standard, mysqlnd, mysqli, Phar, posix, Reflection, mysql, SimpleXML, soap, sockets, imap, tokenizer, xml, xmlreader, xmlwriter, zip, cgi-fcgi, PDO, pdo_sqlite, pdo_mysql
GD: Yes
ImageMagick: No
PHP max upload size: 20M
PHP max form post size: 8M
PHP memory limit: 128M
Total max uploadable file size: 8M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
CONTEXT_DOCUMENT_ROOT: /home/dekorenbloemcom/public_html
DOCUMENT_ROOT: /home/dekorenbloemcom/public_html
GATEWAY_INTERFACE: CGI/1.1
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: PHPSESSID=b7bdd633b1de42f7cbdcb08051827b8a; cmsa=1
HTTP_HOST: dekorenbloem.com
HTTP_REFERER: https://dekorenbloem.com/perch/core/settings/diagnostics/
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8
PATH: /bin:/usr/bin
QUERY_STRING: extended
REDIRECT_STATUS: 200
REMOTE_ADDR: 141.135.212.155
REMOTE_PORT: 35238
REQUEST_METHOD: GET
REQUEST_SCHEME: http
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_FILENAME: /home/dekorenbloemcom/public_html/perch/core/settings/diagnostics/index.php
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
SERVER_ADDR: 195.81.125.82
SERVER_ADMIN: webmaster@dekorenbloem.com
SERVER_NAME: dekorenbloem.com
SERVER_PORT: 80
SERVER_PROTOCOL: HTTP/1.1
SERVER_SIGNATURE: <address>Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at dekorenbloem.com Port 80</address>
SERVER_SOFTWARE: Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
UNIQUE_ID: WL-R@sNRfVIAAHs0AFUAAAAG
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1488966138.26
REQUEST_TIME: 1488966138
argc: 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're on a really old version of the Gallery app. Can you try switching:

$albums = perch_gallery_albums([ 

for

$albums = perch_gallery_album_listing([ 

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.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

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.