bbeer Posted February 12, 2014 Posted February 12, 2014 Hi all I have a newbie question concerning the listing of some child element in an overview. It all works well as long as I have only sub category. In one case I am getting a level deeper, so I only get the first child listet. like trip Overview (Listing all trips) Flying (Lists all children of Lying Biking (Lists all Children ob biking) Holidays (should list the content of its children's children but does not) Italy child 1 child 2 Spain child 1 Croatia child 1 See my code below. <?php $p_id = $page->id; $reisen = $page->find("parent_id=$p_id, sort=reise_abfahrt"); //gets the ID of the page I am on and lists the children echo "id: $p_id"; ?> <dl class="travelList"> <?php foreach ($reisen as $reise) { ?> <dt><a href="<?php echo $reise->url;?>" title="Detailansicht" class="tripDetail"><?php echo $reise->reise_abfahrt;?> <?php echo $reise->longtitle; ?></a></dt> <?php if($reise->reise_flyer != ""){ ?> <dd class="tripRoute"> <a href="<?php echo $reise->reise_flyer->url;?>" title="Flyer als PDF laden" target="_blank" class="tripFlyer">Flyer</a></dd> <?php }?> <?php } ?> </dl> Is there any way I could handle this in the same template as above or do I have to create a special template only for the listing of Holidays? Your help is much appreciatetd.
diogo Posted February 12, 2014 Posted February 12, 2014 $p_id = $page->id !== (hollidays id) ? $page->id : $page->children; Written on the browser and not tested, but theoretically this should work. This is what it does: If we are not on the "hollidays", page parent is this same page, if we are on the "hollidays" page, parents will be all it's children ( $page->children will output something like this: 342|654|877|998 )
diogo Posted February 12, 2014 Posted February 12, 2014 bbeer, I was in a hurry and didn't explain something. You don't have to use the IDs in this case. Same thing could be achived by: $parents = $page !== $page->get('/holidays/') ? $page : $page->children; and, in the selector; $reisen = $page->find("parent=$parents, sort=reise_abfahrt"); Just for reference 2
bbeer Posted February 12, 2014 Author Posted February 12, 2014 thanks, that really helps. Need to get used to pw as soon as possible.
bbeer Posted February 19, 2014 Author Posted February 19, 2014 I really have another question on this now. I have some id's in the same three I would have to hide from this list, lets say 1031 and 1032 how could I do this?
adrian Posted February 19, 2014 Posted February 19, 2014 Just include this in your selector: id!=1031|1032 eg: $reisen = $page->find("parent=$parents, id!=1031|1032, sort=reise_abfahrt"); Be sure to check out the selector test module from Nik - very helpful in figuring these things out: http://modules.processwire.com/modules/process-selector-test/
bbeer Posted February 19, 2014 Author Posted February 19, 2014 Thanks a lot looks so easy if one knows! Really appreciate your help!
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