bwakad Posted April 12, 2014 Share Posted April 12, 2014 I hate to ask this, but since I started building I just have to... My pages are like this: Parentpage (template = parent-template) - child1 (template = child-template) - child2 (template = child-template) - etc My parentpage is actually my main page for a list of childs. On certain fileds from those childs in that list I want to have a link that basically give me back a new filtered list of childs with that field value. My link is like this: <a href='{$pages->find("template=child-template, provincie=$child->provincie")}'>{$child->provincie->title}</a> but hovering displays only 'host/parentpage' If I do it like this: <a href='{$pages->find("provincie=$child->provincie")}'>{$child->provincie->title}</a> hovering displays this: 'host/parentpage/ID|ID' I might be missing the concept here, but I thought a link on any field would make an automatich search and displays the childs... What exactly do I need to do? Is there maybe some search page available? And is there a certain search url I have to use? Link to comment Share on other sites More sharing options...
marcus Posted April 12, 2014 Share Posted April 12, 2014 A) {$pages->find("template=child-template, provincie=$child->provincie")} could result in multiple pages. It's not clear whether you're doing this already, but you'll have to iterate through the results like $children_provincie = $pages->find("..."); // Replace ... with your selector foreach ($children_provincie as $c) { echo $c->url; } ...and so on. B) Even if the selector would return just a single result, you have to return ->url to get it working as a link. Thats because, in your second snippet, you just get an ID instead of a path to the page being found. Link to comment Share on other sites More sharing options...
adrian Posted April 12, 2014 Share Posted April 12, 2014 The logic to find and display specific children should be in the template of the page that is linked to, not the page with the link. Right now you are trying to use a PW array of pages as a URL - that just can't work. You could potentially pass page ids via a url like: mysite.com/children/?ids=1003|1024|1934 but I don't think you have any need for that and it's just way messier than necessary. It sounds like you are trying to link to a page that contains children which have a field with a particular value. In that case I would recommend url segments: mysite.com/children/fieldvalue Then in the template on the children page you need to get the value of the url segment and then do your $pages->find("fieldname={$input->urlSegment1}"); where $input->urlSegment1 is equal to the value of "fieldvalue" that was in the url that go you to this page. This link should get you started: http://wiki.processwire.com/index.php/URL_Segments Link to comment Share on other sites More sharing options...
bwakad Posted April 12, 2014 Author Share Posted April 12, 2014 EDIT --- solved partially, (see also post below) --- My page tree looks like this : ------------------------------------------------ parent - child 1 // item details inclusive custom field name as a link - child 2 // item details inclusive custom field name as a link etc parent has parent-template.php - displays all childs - child url : http://host/parent/itemtitle child has child-template.php - displays a child - url: http://host/parent/itemtitle ------------------------------------------------ provincie // hidden page - custom field - page select - child 1 - child 2 etc Provincie has select-template - without file - template is used site-wide for all page selects : * that way I have 1 template for multiple url segments ! Child has provincie-template.php. *: Branche is a parent page like Provincie, and is using the same select-template. Branche children use branche-template.php ------------------------------------------------ My parent/child url is: http://host/parent/child3 - where child in this case is the item name. My custom field url is: http://host/provincie/child1 - where child in this case is the provincie name. After clicking the custom field link, I get to the 'provincie' page (provincie-template.php) where it GET the url segment '/child1/' and then displays a list for similar items. See post below for code used in provincie-template.php Link to comment Share on other sites More sharing options...
bwakad Posted April 12, 2014 Author Share Posted April 12, 2014 Somehow I overlooked the link in the very bottom of this wiki page that leads to this one: http://wiki.processwire.com/index.php/URL_Segments_in_category_tree_example (See also the post above this one) Code is this: if($input->urlSegment1){ //get the post $post = $pages->get("/$input->urlSegment1/"); if(!$post->id) throw new Wire404Exception(); echo $post->render(); }else{ include("./head.inc"); $category = $page->id; $posts = $pages->find("template=child-template, provincie=$category"); echo "<ul>"; foreach ($posts as $post) { echo "<li><a href='{$post->url}'>{$post->title}</a></li>"; } echo "</ul>"; include("./foot.inc"); } But this only solves the first 'provincie' name. Any other just give me no contents. Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 Deleted all code and started over... Now, on the 'provincie.php' (which is the template for the children) that makes up the value for my 'parent/child/' pages I tried again. But I was unable to GET the $input->urlSegment1 value. This for some reason would not get the value: $select = $pages->find("template=child-template, provincie={$input->urlSegment1}"); Starting with this at the top of the page also not: $myvalue = $input->urlSegment1; echo $myvalue; But when I just use: $select = $pages->find("template=child-template, provincie={$page->title}");foreach ($select as $page) { // do my thing everything seems to be working fine.... hope this is good practise?! Link to comment Share on other sites More sharing options...
adrian Posted April 13, 2014 Share Posted April 13, 2014 Do you have Allow URLSegments turned on in the template's "URLs" tab? Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 yes, just double checked. It's crazy. This thing is keeping me going for the last two days... Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2014 Share Posted April 13, 2014 Quote: foreach ($select as $page) { // do my thing Rings bells. Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 Quote: foreach ($select as $page) { // do my thing Rings bells. Before your replied I already changed it to : $select as $child because I thought this could be an issue. Had to change that in my reply above, sorry 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