Forum

Thread tagged as: Question

Generate Gallery Navigation Dynamically

I want to have a gallery navigation menu showing the gallery hierarchy.

When I am at page Album 1 or Image 1, 2, 3 page, the navigation is shown like this

Album 1
    Image 1
    Image 2
    Image 3
Album 2
Album 3
Album 4

When I am at page Album 2 or Image 4, 5, 6 page, the navigation is shown like this

Album 1
Album 2
    Image 4
    Image 5
    Image 6
Album 3
Album 4

How to generate this kind of navigation? Can you show with example?

Thanks,

Andrew Liu

Andrew Liu 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

In your page:

<ul>
<?php
$albums = perch_gallery_albums(array(
    'skip-template' => true,
));

if (count($albums)) {
    foreach($albums as $album) {
        PerchSystem::set_vars($album);

        perch_gallery_album_images($album['albumSlug'], array(
            'template' => 'gallery_nav.html'
            ));

    }
}
?>
</ul>

And then the gallery/gallery_nav.html template:

<perch:before>
    <li>
        <perch:gallery id="albumTitle" />
        <ul>
</perch:before>
            <li><perch:gallery id="imageAlt" /></li>
<perch:after>
        </ul>
    </li>
</perch:after>

Thank you Drew, this works perfectly. The only thing I don't understand is PerchSystem::set_vars($album); seems there is not difference with or without it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It makes sure the album details are available within the image template - but perhaps they are already.

Thank you!