Roych Posted July 14, 2022 Share Posted July 14, 2022 Hello, I went throughout the forum but nothing similar came up. I need some help with showing selected page reference (page selection) on another page and link to it. I tried al sorts of things and got lost. I have pages like: - Past Events list - (template = "past-events") - Image Gallery - (template = "gallery-album" with page reference field, named "select_event_gallery") Because galleries are added later for each past event, I created a page reference field on gallery page, where you can select the past event to which this gallery should belong to. Then the link (simple button "View Gallery") to this gallery would then be shown on a past event list for a specific selected event. I hope you understand ? I tried with: (shows all galleries and not sure what the url should look like) <?php $galeries = $pages->find("template=gallery-album"); ?> <?php foreach ($galeries as $galery) :?> <a href="<?=$galery->LINK TO GALLERY?>">View Gallery</a> <?php endforeach;?> Ofc. not working. I'm not sure how to approach this so any help is appreciated Thank you R Link to comment Share on other sites More sharing options...
Gideon So Posted July 14, 2022 Share Posted July 14, 2022 Hi @Roych <?php $galeries = $pages->find("template=gallery-album"); ?> <?php foreach ($galeries as $galery) :?> <a href="<?=$galery->select_event_gallery->url; ?>">View Gallery</a> <?php endforeach;?> Gideon Link to comment Share on other sites More sharing options...
Roych Posted July 14, 2022 Author Share Posted July 14, 2022 38 minutes ago, Gideon So said: Hi @Roych <?php $galeries = $pages->find("template=gallery-album"); ?> <?php foreach ($galeries as $galery) :?> <a href="<?=$galery->select_event_gallery->url; ?>">View Gallery</a> <?php endforeach;?> Gideon thank you ?, but this is not working still shows the entire list of all galleries pages. The link should be connected to a gallery page. I want to show "View Galery" button only on, and for selected event. If past event is selected when creating a new gallery (with page reference field) if not, nothing is shown on the event list, because some galleries doesn't belong to events at all.) Event list should look like: (template = "past-events") Past event 1 Past event 2 ("View Gallery" -> event was selected in gallery page ) Past event 3 Past event 4 Past event 5 ("View Gallery" -> event was selected in gallery page) etc ... Thank you R Link to comment Share on other sites More sharing options...
Gideon So Posted July 14, 2022 Share Posted July 14, 2022 I. Hi @Roych I see. I believe there is an individual event template. I think it is better to create a page reference field in the individual event template link the past event to the corresponding gallery page. Then in the event-list template: <?php $ events = $pages->find('template=event'); ?> <?php foreach($events as $event): ?> <?=$event->title ?> <?php if($event->event_gallery->count()): ?> <a href='<?=$event->event_gallery->url; ?>'>Event Gallery</a> <?php endif; ?> <?php endforeach; ?> Link to comment Share on other sites More sharing options...
Roych Posted July 14, 2022 Author Share Posted July 14, 2022 Already tried that, this gives me the entire list of all events in every past event on the list. So I get Event 1 - event1, event2, event3, etc ... Event 2 - event1, event2, event3, etc ... Event 3 - event1, event2, event3, etc ... Link to comment Share on other sites More sharing options...
Gideon So Posted July 14, 2022 Share Posted July 14, 2022 Hi @Roych Did you remove the page reference field in the gallery template and create another page reference field in the event template? Otherwise my code above won't work. Gideon Link to comment Share on other sites More sharing options...
Roych Posted July 14, 2022 Author Share Posted July 14, 2022 5 minutes ago, Gideon So said: Did you remove the page reference field in the gallery template and create another page reference field in the event template? Otherwise my code above won't work. yes I did, still, every event has entire list of events listed under them. Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 14, 2022 Share Posted July 14, 2022 <?php namespace ProcessWire; // in event template $galleriesForThisEvent = $pages->find("template=gallery-album, select_event_gallery=$page->id"); if(count($galleriesForThisEvent)>0) { // show button/s } 1 Link to comment Share on other sites More sharing options...
Roych Posted July 14, 2022 Author Share Posted July 14, 2022 38 minutes ago, wbmnfktr said: <?php namespace ProcessWire; // in event template $galleriesForThisEvent = $pages->find("template=gallery-album, select_event_gallery=$page->id"); if(count($galleriesForThisEvent)>0) { // show button/s } Yes this actualy work as expected, just not sure how to create a link (url) to a gallery. I just had to change $page to $single in your code. I guess something like: <a href="<?=$single->url?>">View Gallery</a> but ofc not working it links to event not gallery. Thank you R Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 14, 2022 Share Posted July 14, 2022 <?php namespace ProcessWire; // in event template $galleriesForThisEvent = $pages->find("template=gallery-album, select_event_gallery=$single->id"); if(count($galleriesForThisEvent)>0) { foreach($galleriesForThisEvent as $gallery) { echo "<a href='$gallery->url'>View Gallery</a>"; } } 1 1 Link to comment Share on other sites More sharing options...
Roych Posted July 14, 2022 Author Share Posted July 14, 2022 Yeees, it's working perfect now. I need to bookmark this. ? Thank you many, many times for help ? R Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now