kkalgidim Posted April 15, 2019 Share Posted April 15, 2019 Hi, I m confused on how to filter results using url segment. It must be very easy question but i can not figure it out. Here is my admin tree Home Clinics Clinic1 Clinic2 Treatments Dental Implant Hair Transplant Locations Turkey Mexico Germany I am using location template, treatment template, clinic template My question is How can i create a link on location template to show the clinics on that location. For ex: on the www.xxx.com/locations/turkey url i have a button called clinics. When i click on that button i want to goto www.xxx.xom/locations/turkey/clinics and it will show the clinics located on Turkey. I hope my explanation clear. Link to comment Share on other sites More sharing options...
dragan Posted April 15, 2019 Share Posted April 15, 2019 Hello @kkalgidim and welcome to PW. Do you use a page reference field to map a clinic to a location? Link to comment Share on other sites More sharing options...
kkalgidim Posted April 15, 2019 Author Share Posted April 15, 2019 Yes. On the clinic page treatment and location uses page reference field. Link to comment Share on other sites More sharing options...
dragan Posted April 15, 2019 Share Posted April 15, 2019 I was assuming you only have a one-to-one relationship when I quickly wrote this, so you'd probably have to slightly alter this basic code: if($input->urlSegment1) { $seg = $sanitizer->name($input->urlSegment1); if($seg === 'clinic') { $loc = $page->name; } $clinic = $pages->get("template=clinic, location=$loc"); $content .= "<p><a href='{$clinic->url}'>{$clinic->title}</a></p>"; } 1 Link to comment Share on other sites More sharing options...
dragan Posted April 15, 2019 Share Posted April 15, 2019 one-to-many would look something like this if($input->urlSegment1) { $seg = $sanitizer->name($input->urlSegment1); if($seg === 'clinics') { $loc = $page->name; } $clinics = $pages->find("template=clinic, location=$loc"); foreach($clinics as $clinic) { $content .= "<p><a href='{$clinic->url}'>{$clinic->title}</a></p>"; } } e.g. a location can have multiple clinics 2 Link to comment Share on other sites More sharing options...
kkalgidim Posted April 16, 2019 Author Share Posted April 16, 2019 Thanks for reply @dragan it will be one-to-many relationship there is 2 template file location.php and list.php xxx.com/location/turkey/ uses location.php template when i enter xxx.com/location/turkey/clinics i want to use list.php template because list will be new designed page. not the part of location template design. how can i achive this? So there is 2 question. 1. how can i assign list template with xxx.com/location/turkey/clinics 2. same code works on list.php template? 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