louisstephens Posted September 18, 2015 Share Posted September 18, 2015 I have been scratching my head on this one for an hour. How do you get the parent (of the current child page) and list all the children for a navigation.? Link to comment Share on other sites More sharing options...
diogo Posted September 18, 2015 Share Posted September 18, 2015 Well, if you want to do literally that $page->parent->children but this is better $page->siblings or, to exclude the current page $page->siblings("id!=$page") or $page->siblings->remove($page) 2 Link to comment Share on other sites More sharing options...
louisstephens Posted September 18, 2015 Author Share Posted September 18, 2015 Ah ha. That was easy enough I did notice that it displays the Id, how would you display the actual Page Name/url? Link to comment Share on other sites More sharing options...
diogo Posted September 18, 2015 Share Posted September 18, 2015 See this example and adapt it to the markup that you want https://github.com/ryancramerdesign/ProcessWire/blob/master/site-beginner/templates/_head.php#L51-L53 Link to comment Share on other sites More sharing options...
louisstephens Posted September 18, 2015 Author Share Posted September 18, 2015 Thanks diogo. I do appreciate the help. Still feeling my way around Processwire (came from Wordpress) and I still am trying to tackle things with that mindset. 1 Link to comment Share on other sites More sharing options...
diogo Posted September 18, 2015 Share Posted September 18, 2015 The beginner profile template files (like the one I linked to) have very well commented examples of these kind of things, have a good look at them. You'll get the hang of it in no time, you'll see Link to comment Share on other sites More sharing options...
louisstephens Posted September 18, 2015 Author Share Posted September 18, 2015 Yeah, I am slowly getting there. I did notice after doing some more research into the basic install that: "// top navigation consists of homepage and its visible children". However, what I was trying to snag were the children of a child. For example: Home - Fish - Bass - Brim - Carp - Site Map - About In the above example, I was trying to pull the children of "Fish". Perhaps I set this up wrong as I couldnt figure out a way to get "Fish" to be top level like Home. Link to comment Share on other sites More sharing options...
diogo Posted September 18, 2015 Share Posted September 18, 2015 In that case, you just have to get the fish page and then get it's children $pages->get("/fish/")->children Or, if you're planning to use that page again later in the code: $fish = $pages->get("/fish/"); $fishChildren = $fish->children; foreach ($fishChildren as $item) { ... } Link to comment Share on other sites More sharing options...
louisstephens Posted September 25, 2015 Author Share Posted September 25, 2015 I thought I had it with: <?php if($page->rootParent->hasChildren) { echo $page->children; } ?> But I guess I am missing something important here. Link to comment Share on other sites More sharing options...
diogo Posted September 25, 2015 Share Posted September 25, 2015 $page->children is an array, you can't echo it directly: foreach($page->children as $child) { echo $child->title; } Link to comment Share on other sites More sharing options...
louisstephens Posted September 28, 2015 Author Share Posted September 28, 2015 Thanks Diogo. I got it with: <?php foreach($page->siblings as $child) { echo "<a href='{$child->url}'>{$child->title}</a>"; } ?> 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