lena Posted January 3, 2017 Share Posted January 3, 2017 Hallo, I need a little help! I build my first processwire website and I don't know how I can choose die pageChildren on the position 5-7 For the children 1-4 I coded for a mainnav and it works. Now I want to do this also for my topnav. But only with the children 5-7. Code for mainnavigation: $root = $pages->get("/"); $children = $root->children("limit=4"); // I get the first 4 pages foreach($children as $child) { if($child->id == wire('page')->id) { echo "<li class='active'><a href='{$child->url}'>{$child->title}<span class='sr-only'>(current)</span></a></li>"; } else { echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; } } Thank you Lena Link to comment Share on other sites More sharing options...
grimezy Posted January 3, 2017 Share Posted January 3, 2017 Hi Lena, If you update to the latest development build you can use the new limit features in your selector. http://processwire.com/blog/posts/pw-3.0.46-stocking-stuffers/#support-for-negative-limit-and-start-values-in-selectors $children2 = $root->children("limit=-2") Notice the minus(-) before the 2. Hope this helps! 2 Link to comment Share on other sites More sharing options...
lena Posted January 3, 2017 Author Share Posted January 3, 2017 Thank you grimezy, i tried and I found another method to solve my problem: with slice() $root = $pages->get("/"); $children = $root->children->slice(4, 3); foreach($children as $child) { if($child->id == wire('page')->id) { echo "<li class='active'><a href='{$child->url}'>{$child->title}<span class='sr-only'>(current)</span></a></li>"; } else { echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; } } 1 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