neonwired Posted August 7, 2019 Posted August 7, 2019 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.
elabx Posted August 7, 2019 Posted August 7, 2019 Try this: https://processwire.com/api/ref/wire-array/get-values/ 1
Robin S Posted August 7, 2019 Posted August 7, 2019 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"; 1
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