Jump to content

How to sort pages by specific template names preserving pagination?


Clarity
 Share

Recommended Posts

Hello everyone!

I have a paginated PageArray and I need to sort the results first by template1, then by template2 and template3 (in any order inside 2 and 3). Then by other templates by any order. Can you please tell me how to do it?

The solution might look something like:

$pages->find('sort=(template=template1,template=template2|template3),...');
Link to comment
Share on other sites

14 hours ago, Clarity said:

The solution might look something like:

$pages->find('sort=(template=template1,template=template2|template3),...');

PW doesn't support that kind of sorting in $pages->find(), but you could use the FindMerge module and do something like this:

$base_selector = "title=foo";
$selectors = [
	"$base_selector, template=template1",
	"$base_selector, template=template2|template3",
	"$base_selector, template!=template1|template2|template3",
];
$pagination_limit = 20;
$results = $pages->findMerge($selectors, $pagination_limit);

 

  • Like 2
  • Thanks 2
Link to comment
Share on other sites

8 hours ago, Robin S said:

PW doesn't support that kind of sorting in $pages->find(), but you could use the FindMerge module and do something like this:

$base_selector = "title=foo";
$selectors = [
	"$base_selector, template=template1",
	"$base_selector, template=template2|template3",
	"$base_selector, template!=template1|template2|template3",
];
$pagination_limit = 20;
$results = $pages->findMerge($selectors, $pagination_limit);

 

Thank you, it indeed works!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...