seddass Posted May 3, 2012 Share Posted May 3, 2012 I am wandering to find out if it is easy something like: "..., sort=template, ..." or "..., sort=template.name, ..." for sorting the pages by their template name in selectors result. When it will be useful: 1. My clients were asking to display the professors first, then doctors, then students in the paginated staff list. 2. Other clients requested to display products pages first in the site search results. I know I could use two search selectors and to concatenate their PageArrays but it will be more complicated with the pagination. I could use a dropdown with "search in products", "search in site" too. Link to comment Share on other sites More sharing options...
ryan Posted May 3, 2012 Share Posted May 3, 2012 Seems like a great idea -- I just now added it in the latest commit. Now it should support the "sort=template". 1 Link to comment Share on other sites More sharing options...
seddass Posted May 3, 2012 Author Share Posted May 3, 2012 Awesome, thanks! Link to comment Share on other sites More sharing options...
Soma Posted May 3, 2012 Share Posted May 3, 2012 Great to have this. Thanks guys. Just to verify, it will "group" and sort by template name? So the problem of having a specific order would only be able with naming the templates according 01-tplx, 02-tply, 03-tplz? Since templates can also have labels this won't be much of a problem I guess. Link to comment Share on other sites More sharing options...
Adam Kiss Posted May 31, 2012 Share Posted May 31, 2012 @Soma - I guess that could work, but this is probably better to use just to group the templates together and then parse the PageArray and set correct order, so you don't run into problem with different orders needed with 'XX-template' system. Example: on search, you need 01-tpl1, 02-tpl2, 03-tpl3. On a different listing, you'll need 03-tpl3, 01-tpl1, 02-tpl2 in this order, and then you're screwed. But this is just a note, you may not run into this issue (if you have one search only, for instance Link to comment Share on other sites More sharing options...
evan Posted August 19, 2016 Share Posted August 19, 2016 Here's my solution for sorting pages by template, with a sort order: // Templates listed in sort order $templates = ['template1', 'template2', 'template3']; // Get pages with templates $results = $pages->find('field=value, template=' . implode('|', $templates)); // Sort results by template $resultsSorted = new \PageArray(); foreach ($templates as $t) { $resultsSorted->import($results->find('template=' . $t)); } // Reassign to $results $results = $resultsSorted; 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