Peter Knight Posted November 15, 2018 Share Posted November 15, 2018 <?php $Cats=$pages->find("parent=1086, id!=$page, sort=sort"); foreach($Cats as $Cat) { echo " I have a selector that pulls in 4 child pages of a parent and the order is set to reflect the order of the tree. My client has asked that instead of Cat 1 | Cat 2 | Cat 3 | Cat 4 we instead display Cat 4 | Cat 1 | Cat 2 | Cat 3 However, I can't change the sort order in the tree. Can anyone guide me on the correct approach here? Thanks Link to comment Share on other sites More sharing options...
Robin S Posted November 15, 2018 Share Posted November 15, 2018 The item you want to give special treatment to is the last item in the WireArray, so you could use pop() to get that item and remove it from the WireArray: Alternatively here is a more flexible approach that you can use for any item in the WireArray: 8 Link to comment Share on other sites More sharing options...
Peter Knight Posted November 16, 2018 Author Share Posted November 16, 2018 Thanks Robin. These are new to me but I get the general mechanics. What is the console part of your screenshots ? A module? Link to comment Share on other sites More sharing options...
Robin S Posted November 16, 2018 Share Posted November 16, 2018 2 minutes ago, Peter Knight said: What is the console part of your screenshots ? A module? It's the infinitely useful Console panel in Tracy Debugger: https://adrianbj.github.io/TracyDebugger/#/debug-bar?id=console 4 Link to comment Share on other sites More sharing options...
Tom. Posted November 16, 2018 Share Posted November 16, 2018 I believe that ProcessWire automatically sorts out duplicates so you could do $Cats = $pages->find("parent=1086, id!=$page, sort=sort"); $Cats->prepend( $Cats->eq(4) ); foreach($Cats as $Cat) { } 2 Link to comment Share on other sites More sharing options...
horst Posted November 16, 2018 Share Posted November 16, 2018 @Peter Knight why do you cannot sort the pages manually, or let the client sort them manually? Link to comment Share on other sites More sharing options...
Peter Knight Posted November 16, 2018 Author Share Posted November 16, 2018 1 hour ago, horst said: @Peter Knight why do you cannot sort the pages manually, or let the client sort them manually? I can't sort them manually because the order is used in other layout components across the site. Technically I could build an extra kind of sortable page list but I also want to keep this really simple for a client who will be maintaining the site. 1 Link to comment Share on other sites More sharing options...
Peter Knight Posted November 23, 2018 Author Share Posted November 23, 2018 On 11/16/2018 at 11:16 AM, Tom. said: I believe that ProcessWire automatically sorts out duplicates so you could do $Cats = $pages->find("parent=1086, id!=$page, sort=sort"); $Cats->prepend( $Cats->eq(4) ); foreach($Cats as $Cat) { } Hi Tom Thanks for this. I had unexpected results with this and I think I know why. My array consists of 4 items (Categories) so $Cats->prepend( $Cats->eq(4) ); works until I hide the current Category. Essentially this means the array only consists of 3 Categories and the page throws an error. That's only my guess. If I do $Cats->eq(3) etc or a lower number it works. On 11/15/2018 at 9:24 PM, Robin S said: Alternatively here is a more flexible approach that you can use for any item in the WireArray: Worked for me. Thanks @Robin S 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