Forum

Thread tagged as: Question

gallery app 2 questions

I know it's old hat now but I have several clients still using the gallery app on Perch V2

1 question how would I filter the listing of albums to only show albums added in last 2 years, rather than all albums that shows with the following code

<?php perch_gallery_album_listing(); ?>

2 question how can you get album.php to show by default on page load the latest album added, ie NOT a list of albums that viewer then has to select one to see

currently I am using a hard coded link to album.php with the slug of a specific album and the page has the following

    <?php 
        if(isset($_GET['s'])) {

            // Output the large images
            $opts = array(
               'template'   =>'d_list_image.html'
            );
            perch_gallery_album($_GET['s'], $opts);

            // Output the small images used for navigation
            $opts = array(
               'template'   =>'d_nav_image.html'
            );
            perch_gallery_album($_GET['s'], $opts);
        }

        ?>
Charlie Elsey

Charlie Elsey 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do your albums have dates? Both those questions are time-based.

thanks drew, yes they have dates, here is album template. My problem is I am an idiot when it comes to filtering and arrays... thanks for any help :)

<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="date" type="date" label="Date" format="%d %B %Y" required="true"/>

Drew McLellan

Drew McLellan 2638 points
Perch Support

To get the latest album, you need to sort by your date field

'sort' => 'date',
'sort-order' => 'DESC',
'count' => 1,

thanks so much Drew, so I could change count to give a few more for the album listings, which will work for my client purposes.

but how would I use that code on the album page? in the array and get rid of the slug reference? not sure how I would format that...

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean by the album page? What code do you have? Is it what's above?

album.php and yes it has that code block shown in my first question... thanks so much. So currently I have to manually update links to the album page to show latest album eg .../album.php?s=spring-2017 Whereas it would be nice if the url was just .../album.php and it showed the latest album

btw the sort above works great on just the listings when used in here <?php perch_gallery_album_listing(); ?> so thanks very much

so using the code below outputs no html, no doubt because the page in question has no slug selected

It must surely be simple to do this - code that just displays the latest album on page load, but I can't figure it out :(

                <?php 
            if(perch_get('s')) {

                // Output the large images
                perch_gallery_album_images(perch_get('s'), array(
                   'template'   =>'d_list_image.html',
                          'sort' => 'date', 
          'sort-order' => 'DESC', 
          'count' => 1,
                ));

                // Output the small images used for navigation
                perch_gallery_album_images(perch_get('s'), array(
                   'template'   =>'d_nav_image.html',
                          'sort' => 'date', 
          'sort-order' => 'DESC', 
          'count' => 1,
                ));
            }

            ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm a bit lost. Going back to your question:

how would I filter the listing of albums to only show albums added in last 2 years

You'd filter for a date greater than today's date two years ago:

perch_gallery_album_listing([
    'filter' => 'date',
    'match' => 'gt',
    'value' => date('Y-m-d H:i:s', strtotime('-2 YEARS')),
]);

how can you get album.php to show by default on page load the latest album added

That's going to be two steps. Find the album, then show its images.

$albums = perch_gallery_album_listing([
    'skip-template' => true,
    'count' => 1,
    'sort' => 'date',
    'sort-order' => 'DESC',
]);

perch_gallery_album_images($albums[0]['albumSlug']);

"I'm a bit lost" You are not alone! Luckily only one of us is a dimwit. Question 1 is sorted thanks, Question 2 is the remaining issue...

so OK "That's going to be two steps. Find the album, then show its images." now we are on the right track, so how would I use that code in your second block to output using my tempaltes for display as above.

Thanks for your patience Drew

Drew McLellan

Drew McLellan 2638 points
Perch Support

Just add the template option.

Ok I've tried this which does not output content (html output terminates at point of insertion) and in my editor I am getting a syntax error warning about the first block

 <?php 
$albums = perch_gallery_album_listing([
 'skip-template' => true, 
'count' => 1, 
'sort' => 'date', 
'sort-order' => 'DESC', ]); 


// Output the large images
perch_gallery_album_images($albums[0]['albumSlug'], array(
 'template'   =>'d_list_image.html',

));

// Output the small images used for navigation
perch_gallery_album_images($albums[0]['albumSlug'], array(
'template'   =>'d_nav_image.html',

));

?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What error are you getting?

html output on live page terminates at the point of that php code. no specific error, just a warning about a syntax error

If I change first block of code to that below I no longer have syntax error but still no html output

<?php 
$albums = perch_gallery_album_listing(array(  
'skip-template' => true,  
'sort' => 'date', 
'sort-order' => 'DESC',
'count' => 1, 
)); 
Drew McLellan

Drew McLellan 2638 points
Perch Support

My guess is that you're on PHP 5.2. The current version is 7.1.

That code doesn't out anything. It populates the $albums variable, which is then used in the second block to get the images.

Sorry this is taking so long Drew

we were on 5.2, updated to 7.0, the code below still outputs nothing in html - output ends at insertion point.

have I correctly coded the template array below?

<?php 
$albums = perch_gallery_album_listing([
 'skip-template' => true, 
'count' => 1, 
'sort' => 'date', 
'sort-order' => 'DESC', ]); 

// Output the large images
perch_gallery_album_images($albums[0]['albumSlug'], array(
'template'   =>'d_list_image.html',

 ));

// Output the small images used for navigation
perch_gallery_album_images($albums[0]['albumSlug'], array(
'template'   =>'d_nav_image.html',

 ));

?>

I also tried this, still no html output

    <?php 
        $albums = perch_gallery_album_listing([ 
        'skip-template' => true, 
        'sort' => 'date', 
        'sort-order' => 'DESC',
        'count' => 1, 
        ]);  
         // Output the large images
        $opts = array(
        'template'   =>'d_list_image.html',
        'sort' => 'date', 
        'sort-order' => 'DESC',
        'count' => 1,
            );
        perch_gallery_album_images($albums[0]['albumSlug'], $opts);

        // Output the small images used for navigation
        $opts = array(
        'template'   =>'d_nav_image.html',
        'sort' => 'date', 
        'sort-order' => 'DESC',
        'count' => 1,
            );
        perch_gallery_album_images($albums[0]['albumSlug'], $opts);

        ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you getting any errors logged?

no errors logged, sorry. The html output IRL just terminates at the point this block of code is situated on the page. Does all that code look OK to you Drew? It seems such a simple thing, I can't get my head round why it is so hard to achieve :(

Drew McLellan

Drew McLellan 2638 points
Perch Support