x
 
Create New Page

Revision: Adding an option to sort by edit date

Revision from: 16:47, 18 Aug 2006

Changes are made at your own risk and are not guaranteed, either by the author or the administrator, to work. You should always make backups of the original files so that you can revert back to them, as well as backups of the database in case you really mess up.

Best Practice
Make a duplicate copy of your original weblog template group, or create a backup copy. This allows you to rollback quickly to a pristine version of the original templates.

Also, note with hacks that they are dangerous and can cause your site to stop working. They also make later updates to EE more difficult and you should track the hacks you use if you are going to use them, or you may lose the functionality later on down the line when you upgrade.

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: