Jump to content

Recommended Posts

Posted
<?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

 

Posted

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:

2018-11-16_102038.png.3741e5afbd3fd5c0f86c2eafa3f96c14.png

 

Alternatively here is a more flexible approach that you can use for any item in the WireArray:

2018-11-16_102130.png.0fa824632484d52531ec24822d0a02b8.png

  • Like 8
Posted

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) {
}

 

  • Like 2
Posted
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.

 

  • Like 1
Posted
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:

2018-11-16_102130.png.0fa824632484d52531ec24822d0a02b8.png

 

Worked for me. Thanks @Robin S

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
×
×
  • Create New...