Sort page list by last edited

Permalink 2 users found helpful
Is there a way to have a page list display the pages in order of when they were last updated/edited?

I want to use it in a portfolio section where it will show the latest, or most recently updated, client.

hursey013
 
hursey013 replied on at Permalink Reply
hursey013
Bump - any ideas on this, thought there might be some api call I could tie into with to accomplish this but I'm not finding anything. Appreciate any ideas or thoughts!
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Just came across this post:
http://www.concrete5.org/community/forums/customizing_c5/donand039t...

Perhaps you can do something like that? Override the page_list controller and in the switch statement in the getPages() function, change one of the cases (one that you don't normally use -- e.g. "alpha_desc") to call this instead:
$pl->sortBy('cvDateCreated', 'desc');
Then choose the "Alphabetical Descending" sort order in the page list block and it will sort it by the version's created date (which is equivalent to the last modified date) instead.

HTH
hursey013 replied on at Permalink Reply
hursey013
worked like a charm, thanks for the snippet!
BPSIndy replied on at Permalink Reply
I'd like to add on to the helpful reply given by jordanlev with some more detail and additional options based on our similar situation.

We've added a "news release date" custom attribute to pages of page-type "news release". When we want to show a list of news releases we typically want them to show in "news release date" order, descending. So we have a custom sort order based on a custom attribute and it's only for a certain custom page type - i.e. I would rather NOT use the "alpha_desc" or "alpha_asc" choice for this. I want to leave them alone just in case I actually need them.

What I did that worked for me (C5 version 5.6) :

1. Create a folder /page_list under my /root/blocks
2. Copied controller.php from /root/concrete/blocks/page_list to root/blocks/page_list
3. Copied the entire function getPageList from /root/concrete/core/controllers/blocks/page_list.php and inserted it into the PageListBlockController class of /root/blocks/page_list/controller.php
4. Found the
switch($row['orderBy']) {
statement and added the following before the
default:
line:
case 'news_release_asc': // added to used news release date
  $pl->sortBy('ak_news_release_date', 'asc');
  break;
case 'news_release_desc': // added to used news release date
  $pl->sortBy('ak_news_release_date', 'desc');
  break;

5. Copied page_list_form.php from /root/concrete/blocks/page_list to /root/blocks/page_list

6. Found the
<select name="orderBy">
statement where the user can choose the sort order of the page-list and added the following after the
<option value="alpha_desc"
line:

<option value="news_release_asc" <?php  if ($orderBy == 'news_release_asc') { ?> selected <?php  } ?>><?php echo t('with the earliest news release first')?></option>
<option value="news_release_desc" <?php  if ($orderBy == 'news_release_desc') { ?> selected <?php  } ?>><?php echo t('with the most recent news release first')?></option>


Hopefully this will help someone who was/is in a similar situation to ours.
AccountDisabled replied on at Permalink Reply
Thank you so much for the detailed how-to. Saved me hours and hours of research!