Jump to content

Show page reference field on another page and connect


Roych
 Share

Recommended Posts

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

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

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

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

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

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

<?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>";
    }
}

 

  • Like 1
  • Thanks 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...