MarcC Posted January 16, 2013 Share Posted January 16, 2013 On the front end of a website I'm working on, I would like to sort some pages ("Project") by the nearest due date of their children. Here's an example: Before: Project 1 Assignment -- Due Date 20 January 2012 Assignment -- Due Date 21 January 2012 Project 2 Assignment -- Due Date 18 January 2012 Assignment -- Due Date 19 January 2012 After: Project 2 Assignment -- Due Date 18 January 2012 Assignment -- Due Date 19 January 2012 Project 1 Assignment -- Due Date 20 January 2012 Assignment -- Due Date 21 January 2012 Any tips on a good way to do this? Thanks. I can already sort the children fine, but the parents I dunno. Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2013 Share Posted January 16, 2013 I don't see an easy option to do that, but with a little module you could on each save of a child page update a date field on the parent. Then sort it by that field. Let us know so we can help you get started. 3 Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2013 Share Posted January 16, 2013 Edit well if there not too many projects you could try and evaluate the dates and store them on runtime to sort by that value afterwards when you loop them out. $pa = $pages->find("template=project"); if(count($pa)){ foreach($pa as $p){ if(!$p->numChildren) continue; // no assignments // store a temporary value to the project page $p->tmp_date = $p->children("sort=-due_date")->first()->due_date; } // output the projects foreach($pa->sort("-tmp_date") as $p){ echo "<li>$p->title</li>"; if(!$p->numChildren) continue; foreach($p->children("sort=-due_date") as $a){ // output assignments } } } This will work well if you don't have thousands of pages. The module approach would be the more efficient and scaleable. 4 Link to comment Share on other sites More sharing options...
MarcC Posted January 17, 2013 Author Share Posted January 17, 2013 Thanks Soma. We won't have thousands of pages, maybe a hundred max. So I'll try the code you were kind enough to provide. Link to comment Share on other sites More sharing options...
antknight Posted May 7, 2013 Share Posted May 7, 2013 I had a problem here but figured it out, with Somas help 2 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