Forum

Thread tagged as: Question, Gallery

Gallery - Example B - link to album instead of index?

This seems like it should be very simple, but I'm afraid I'm not getting it or can't find it in the documentation.

In my gallery folder I've got:

  • an index page using perch_gallery_albums() to list the albums and link to them
  • an album page using the code block below to link to a very slightly modified version of the b_static_list_image template (I removed the H2 and album description, didn't touch anything else)
  • and an image page which is a copy of the Example B image page.

Album page:

<?php
  if(perch_get('s')) {
    perch_gallery_album_details(perch_get('s'));
    perch_gallery_album_images(perch_get('s'), array(
          'template'   =>'list_image.html'
  ));
} ?>

On the image page, there's a link "back to listing" which goes to index.php. I'd like to change it to link back to the album page, but obviously it doesn't know which album I mean until I tell it.

I've got this: <p><a href="album.php?s=<perch:gallery id="albumSlug" />">« Back to album</a></p> but that gives me a broken link in the markup, like so: <p><a albumslug"="" href="album.php?s=<perch:gallery id=">">« Back to album</a></p>

How should I actually identify which album the current image belongs to, so I can link to that one dynamically instead of creating a static page for each album?

Julie Grundy

Julie Grundy 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does <perch:showall /> list the album slug you need to form the link?

Yes, putting <perch:showall /> on list-image.html (my version of b_static_list_image.html) gives me a nice list of all the info including the album slug, title and ID.

Using the slug I can hardcode the link on image.php like this: <a href="album.php?s=test-album"> and that creates a working link back to album.php with the Test Album content loaded. If I hardcode it to my other album, imaginatively named Second Test, that links back to album.php but with the Second Test content loaded. However I'd like to avoid hardcoding it if possible.

I wasn't able to use showall on the image.php page though - I guess because it's not a template, as such, so that command doesn't apply there. But should it be a template after all? I had just copied the page up one level from the Example B folder to the gallery folder, and edited it to use my header and footer instead of the sample one. But maybe that's not the best method?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to use

<perch:gallery id="albumSlug" />

in your template to form the link.

OK, so I was a bit confused before about where to put the showall command. I had it on the album, not the image page. Sorry about that, not very helpful!

So now I've added it to b_static_image.html, and it doesn't actually reveal an album slug, just an ID. This is what the static image page looks like now:

<img src="<perch:gallery id="main" />" alt="<perch:gallery id="imageAlt" />" height="<perch:gallery id="main-h" />" width="<perch:gallery id="main-w" /> "/>
<!--<a href="album.php?id=<perch:gallery id="albumSlug" />">Back to album</a>-->
<a href="album.php?id=<perch:gallery id="albumID" />">Back to album</a>
<perch:showall />

But using slug or ID takes me back to an empty album.php?id=1 url, it doesn't seem to be picking up the album content.

What have I still got wrong here? Is there any more info I can provide that would reveal the problem?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you don't have the album slug available then you may need to pass it into the page when you link to the page. You'd then have it to be able to form the link back to the album.