Jump to content

Get pages index in a pagearray


neonwired
 Share

Recommended Posts

Is there an easy way to get a pages index within a given pagearray similar to how $page->index() works with siblings. I'm trying to do a index of total count but using all pages of a grand parent page so essentially using all siblings and cousins.

Link to comment
Share on other sites

If you are looping over the whole PageArray then the sort position is the key (zero indexed).

foreach($items as $key => $item) {
    echo "$item->title - sort position is $key";
}

If you want to get individual pages from the PageArray and know their sort position you can first loop over the PageArray and save the sort position to a custom property on each page.

foreach($items as $key => $item) {
    $item->sort_position = $key;
}
$one = $items->get("foo=bar");
echo "$one->title - sort position is $one->sort_position";

 

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...