Page List - Custom date attribute sorting
Permalink 1 user found helpful
Hi,
I'm trying to sort my posts by a custom date attribute, I believe I've found the right part in the page list controller file, though can't seem to get it working.
I have tried adding "ak_" before my attribute handle, and "asc" after it like this post suggests:
https://www.concrete5.org/community/forums/customizing_c5/sort-page-...
Though can't seem to get any result from it.
I'm trying to sort my posts by a custom date attribute, I believe I've found the right part in the page list controller file, though can't seem to get it working.
switch($row['orderBy']) { case 'display_asc': $pl->sortByDisplayOrder(); break; case 'display_desc': $pl->sortByDisplayOrderDescending(); break; case 'chrono_asc': $pl->sortByPublicDate(); break; case 'alpha_asc': $pl->sortByName(); break; case 'alpha_desc': $pl->sortByNameDescending();
Viewing 15 lines of 23 lines. View entire code block.
I have tried adding "ak_" before my attribute handle, and "asc" after it like this post suggests:
https://www.concrete5.org/community/forums/customizing_c5/sort-page-...
Though can't seem to get any result from it.

bump
Did you ever get this working. I too have tried as suggested in that post.
Here's what worked for me:
I found that I couldn't get the controller to work in my blocks folder of the package, it had to be in my override folder, but I was able to create the attribute itself via the package controller though.
Hope this helps.
Here's what worked for me:
$cArray = array(); switch($row['orderBy']) { ... case 'updated_page_desc': // added to use updated pages(if applicable) $pl->sortBy('ak_publish_date'); break; default: $pl->sortByPublicDateDescending(); break;
I found that I couldn't get the controller to work in my blocks folder of the package, it had to be in my override folder, but I was able to create the attribute itself via the package controller though.
Hope this helps.
NM -
I changed a date and the sort broke so this is still an issue
I changed a date and the sort broke so this is still an issue
I did actually get it working with sortByMultiple('attribute_handle');
In my code before I wasn't passing the handle in the right place (derp).
I too couldn't override the correct file, BUT found you can do it in the page_list controller at /public_html/blocks/page_list/controller.php
Here's my code:
In my code before I wasn't passing the handle in the right place (derp).
I too couldn't override the correct file, BUT found you can do it in the page_list controller at /public_html/blocks/page_list/controller.php
Here's my code:
switch($row['orderBy']) { case 'sub_entry_date_asc': $pl->sortByMultiple('ak_sub_entry_date asc', 'cName asc'); break; case 'sub_entry_date_desc': $pl->sortByMultiple('ak_sub_entry_date desc', 'cName asc'); break; case 'display_asc': $pl->sortByDisplayOrder(); break; case 'display_desc': $pl->sortByDisplayOrderDescending(); break; case 'chrono_asc': $pl->sortByPublicDate();
Viewing 15 lines of 26 lines. View entire code block.
Thanks for the heads up - it's weird. This sort of works, but somehow the system doesn't seem to be pulling the date attribute correctly, so it's sorting, but some of the dates are out of order.
example: my attribute: publish_date has values: 11/1/13, 10/10/13, 9/2/13 and 12/6/11. I have my controller set to.
So it prints: 11/1/13, 9/2/13, 10/10/13, 12/6/11
if I change it to ascending order, it prints: 12/6/11, 11/1/13, 9/2/13, 10/10/13
This leads me to believe it's somehow sorting some other way entirely, but for the life of me I can't figure out what that is.
example: my attribute: publish_date has values: 11/1/13, 10/10/13, 9/2/13 and 12/6/11. I have my controller set to
sortBy('ak_publish_date','desc')
So it prints: 11/1/13, 9/2/13, 10/10/13, 12/6/11
if I change it to ascending order, it prints: 12/6/11, 11/1/13, 9/2/13, 10/10/13
This leads me to believe it's somehow sorting some other way entirely, but for the life of me I can't figure out what that is.
To save confusion, which way around is d/m/y ? I can't actually figure out which is meant to be what? If you are not a yank, the asc one seems to work as 12/6/11, 11/1/13, 10/10/13
ah sorry, I am a yank :-)
that list is in month day year.
I did figure out that I might not have had the same strings/types exactly. I noticed my output was parsing the datetime object into two different formats , because I used date('F j, Y') as one output which gave me something like: December 6, 2011 for one pagelist item and strftime('%B %d, %Y') as another which game me December 06, 2011 on another one.
Voilà! Now that I'm using the same format for both, the sort seems to actually be working as expected.
that list is in month day year.
I did figure out that I might not have had the same strings/types exactly. I noticed my output was parsing the datetime object into two different formats , because I used date('F j, Y') as one output which gave me something like: December 6, 2011 for one pagelist item and strftime('%B %d, %Y') as another which game me December 06, 2011 on another one.
Voilà! Now that I'm using the same format for both, the sort seems to actually be working as expected.
Lol it's cool... Yanks are fun!
Woo, good job!
Woo, good job!