Jump to content

Navigation only for children 5-7


lena
 Share

Recommended Posts

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

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>";
            }    
       }


 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...