x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Adding an option to sort by edit date

Changes are made at your own risk and are not guaranteed to work. Always make backups of the database and files prior to implementing hacks. Make a special backup of the file and/or template you are modifying so that you can roll back quickly.

Hacks are dangerous and can cause your site to stop working. They make later updates to ExpressionEngine more difficult; you should track your hacks for post-update re-implementation. 

Most hacks are unnecessary, please review the Development Documentation for information on expanding ExpressionEngine via Modules, Extensions, and Plugins.

Hacks are never officially supported.

About

This hack will allow you to sort your entries in the control panel based on their edit dates.

Step 1

Open up system/cp/cp.publish.php. On line 5063, look for this:

$sel_1 = <nowiki>''</nowiki>; $sel_2 = <nowiki>''</nowiki>; $sel_3 = <nowiki>''</nowiki>;

Immediately after this, add the following:

// START HACK (Sort by edit date)
$sel_4 = <nowiki>''</nowiki>; $sel_5 = <nowiki>''</nowiki>;
// END HACK (Sort by edit date)

Step 2

On line 5072, look for this:

$sel_3 = ($order == 'alpha') ? 1 : <nowiki>''</nowiki>;

After this line, add the following:

// START HACK (Sort by edit date)
$sel_4 = ($order == 'edit_asc') ? 1 : <nowiki>''</nowiki>;
$sel_5 = ($order == 'edit_desc') ? 1 : <nowiki>''</nowiki>;
// END HACK (Sort by edit date)

Step 3

On line 5082, look for this:

$DSP->input_select_option('desc', $LANG->line('descending'), $sel_1).

After this line, add the following:

// START HACK (Sort by edit date)
$DSP->input_select_option('edit_asc', 'Oldest Edited First', $sel_4).
$DSP->input_select_option('edit_desc', 'Newest Edited First', $sel_5).
// END HACK (Sort by edit date)

Step 4

On line 5363, look for:

case 'alpha' : $end .= "title asc";
break;

After these lines, add the following:

// START HACK (Sort by edit date)
case 'edit_asc'    : $end .= "edit_date asc";
break;
case
'edit_desc'    : $end .= "edit_date desc";
break;
// END HACK (Sort by edit date)

Screenshot

Once you have installed the hack, the Order dropdown on the Edit page should look like:

1d453e290d697b4d59be8dcd22d9b7f2

Optional Step

The words “Oldest Edited First” and “Newest Edited First” are hardcoded in English. If you want to add support for multiple languages, you will have to replace the code in Step 3 with

// START HACK (Sort by edit date)
$DSP->input_select_option('edit_asc', $LANG->line('edit_ascending'), $sel_4).
$DSP->input_select_option('edit_desc', $LANG->line('edit_descending'), $sel_5).
// END HACK (Sort by edit date)

Then you will have to add the following into your lang.publish.php file:

"edit_ascending" =>
"Oldest Edited First",

"edit_descending" =>
"Newest Edited First",

Then you can translate “Oldest Edited First” and “Newest Edited First” to whatever language you like. Since this involves editing two files, I did not include it in the original hack, as I wanted to alter as little files as possible.

Category:Hacks

Categories: