Jump to content

Gallery with "virtual" detail-pages


sn4ke
 Share

Recommended Posts

Good evening together,

I'm currently working on my second website using PW and coming along very good... But now I face a Problem:

I want to use the "Image" Fieldtype to populate a gallery-page (for example "photos/holiday-2012/") - Here I display all the thumbs.

When clicking on an image I'd like to open the image on it's own detail-page (with the description underneath etc.) - The URL should look something like "photos/holiday-2012/<image-name>" ...

I'm not sure if the pager will do the trick - Is there any easy way to simulate this "detail-pages" since these pages will never exist?

Info: The gallery-page will never have any child-pages, so I don't have to worry about naming conflicts. I also searched the forum for "gallery", "virtual", "page" and "pseudo-pages" but could not find someone with a similiar problem :(

Link to comment
Share on other sites

Hi there - I think you need to go to the template for holiday-2012, select URLs and then tick "Allow URL segments". You can then simply add the image name as the first URL segment and test for that in your code.

If this isn't clear, let me know and I'll find you a code sample.

Link to comment
Share on other sites

You could use page segments to do this. You will have to activate them for the gallery-page template, on the URLS tab of the template setup.

Well use the number of the position of the image in the field. It seems to me that it's the best way to ensure it's uniqueness.

On the template file do something like this:

if ($input->urlSegment1) {
 $index = (int) $input->urlSegment1; // use (int) to sanitize, since we want a number
 $image = $page->imagesField->index($index); // get the image in the correspondent position
 echo "<img src='{$image->url}'/>;
}else{
 ...rest of the code...
}

on the normal code of the template you can put on the thumbs:

$i = 0;
foreach($page->imagesField as $image){
 <a href="{$page->url}{$i}"><img src='$image->width(100)->url'/></a>;
 $i++;
}

This will give us, for each thumbnail, a link like "photos/holiday-2012/n"

PS: Gazley, just read your answer before posting mine. I don't think it's that simple as you say, so, here it goes :)

But I might be wrong...

Link to comment
Share on other sites

*gasp*

Thanks guys! I wasn't expecting such a fast respond!

ProcessWire just keeps amazing me... Such a simple solution ;) The URL segments are just exactly what I needed.

The next question will be a bit more tricky - But I'll save that for tomorrow or so...

Thanks again, both of you :)

Link to comment
Share on other sites

@diogo - I'm working on a photography site right now and am doing something quite similar. The approach I outlined seems to work OK for me but doubtless, there are other (maybe better) ways of resolving this requirement.

Either way, sn4ke seems happy enough ;)

Cheers!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...