Jump to content

How to get the index number of a page with siblings?


kixe
 Share

Recommended Posts

To get a page by index number from a PageArray is easy:

/* returns a page object */
$pagebyindex = $myparentpage->children->eq(integer $num);

Now I needed a function which returns the Index of the page from the siblings. It took me a while to figure this out, and I like to share this here:

/* returns an integer */
$indexbypage = $myparentpage->children->getItemKey($page); // or
$indexbypage = $page->siblings->getItemKey($page);

Found this information in http://cheatsheet.processwire.com/ under section PageArray/WireArray and here:

http://processwire.com/apigen/
To get complete information about API this page is your (and my) friend.

Have a nice day :rolleyes:

  • Like 5
  • Thanks 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...