Jump to content

Sorting and subfolders


Nils Wiere
 Share

Recommended Posts

This must be simple, however, I couldn't figure out how to do it. I got this structure in the admin tree:

Page 1 [Template A]

    Children 1-1 [Template B]
    Children 1-2 [Template B]
    Children 1-3 [Template B]
    ...

Page 2 [Template A]

    Children 2-1 [Template B]
    Children 2-2 [Template B]
    ...

Page 3 [Template A]

    Children 3-1 [Template B]
    ...

What I want in the front end, is this sort order:

Children 1-1
Children 1-2
Children 1-3
Children 2-1
Children 2-2
Children 3-1

Plus, the order should depend on the order in the admin tree. So, if I move Page 3 on top of the tree, the children of Page 3 should appear first.

I tried this, but the order seemed to be random (without a connection to the order in the admin tree):

$pages->find("template=B, sort=sort");

I also tried this, and again I got a random looking order:

$pages->find("root.template=A, sort=sort");

Do you have any idea?

Thanks,
Nils

Link to comment
Share on other sites

Hi @Nils Wiere

Try this:

$pages->find("template=B, sort=parent.title, sort=sort");

or this

$pages->find("template=B, sort=parent.sort, sort=sort");

Not sure that this will work, but give a try.

As alternative:

$parents = $pages->fint("template=A, sort=sort");
$items = new PageArray; 
foreach($parents as $parent) {
	$items->import($parent->children("sort=sort"));
}

 

  • Like 6
Link to comment
Share on other sites

I knew there's an easy solution (as always in ProcessWire) – thanks Zeka!

I wasn't aware that we have a sort option "parent.sort".

So for me, this was the solution:

$products = $pages->find("template=B, sort=parent.sort, sort=sort"); 

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