Recently in Hacks Category

Using MTML, you can sort assets by label in an entry context like this:

<mt:EntryAssets sort_by="label">
    <!-- asset content here -->

However on the Edit Entry screen the filename for each asset is listed, but the assets are not sorted by filename.

The following steps will update the Edit Entry/Page screen to list assets by asset label…

Three App Templates to Edit


Update the template that produces the Edit Entry/Page screen.

  1. Line 491:

    <mt:var name="asset_name">

    Change to:

    <mt:var name="asset_label"> [<mt:var name="asset_name">]


Update the script that collects the assets in the sidebar of the Edit Entry/Page screen.

  1. Line 191:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_thumb => $asset->thumbnail_url(Width=>100)};

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label, asset_thumb => $asset->thumbnail_url(Width=>100)};
  2. Line 193:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
  3. Line 201:

    my $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};

    Change to:

    my $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
  4. Line 210:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_thumb => $asset->thumbnail_url(Width=>100)};

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label, asset_thumb => $asset->thumbnail_url(Width=>100)};
  5. Line 212:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
  6. Line 217: This will sort assets by asset_label:

    $param->{asset_loop} = $assets;

    Change to:

    $param->{asset_loop} = [ map $_->[1], sort { $a->[0] cmp $b->[0] } map { [ $_->{asset_label}, $_ ] } @$assets ];


Update the script that inserts the asset into the list of assets once selected.

  1. Line43

    myAssetLink.appendChild(document.createTextNode('<mt:AssetLabel encode_js="1"> [<mt:AssetFileName encode_js="1">]'));

    Change to:

    myAssetLink.appendChild(document.createTextNode('<mt:AssetFileName encode_js="1">'));

Without using a plugin, the best method for user-defined ordering of pages and entries is to sort by authored_on date.


<mt:Entries sort_by="authored_on">
    <!-- entry content here -->


<mt:Pages sort_by="authored_on">
    <!-- page content here -->

The authored_on date for entries can easily be updated using the “batch edit” functionality in the “More actions…” menu on the Manage Entries listing screen.

Because pages are listed by modified_on the “batch edit” functionality also uses the modified_on date. This is bad because the next time the page is saved, the modified date will be updated. (I submitted a bug about this some time ago.).

So follow along as we make a few changes to two Movable Type application templates to update Manage Pages screen (and the batch edit functionality for pages) use the authored_on date instead of the modified_on date.

Note: We could just update the batch edit mode to use the authored_on date, but it would be more useful to update the Manage Pages screen to also use the authored_on date so that pages will be listed in the same order they will appear in the templates.

These steps were tested in versions MT4.32 and MT4.261 but will work for all versions of MT4.x and MT5.0 as well.

Tip: Always make a backup of a default file before modifying it; I duplicate the file and place a ~ after it:

cp file.mtml file.mtml~

Two App Templates to Edit


One change repacing the table header label:

  1. Search for (line 79):

    <th class="date"><mt:if name="object_type" eq="page"><__trans phrase="Last Modified"><mt:else><__trans phrase="Created"></mt:if></th>

    Replace with:

    <th class="date"><__trans phrase="Created"></th>


Three changes replacing modified_on with authored_on where conditioning based upon $type eq 'page':

  1. Search for (line 547):

    $arg{'sort'} = $type eq 'page' ? 'modified_on' : 'authored_on';

    Replace with:

    $arg{'sort'} = 'authored_on';
  2. Search for (line 1726):


    Replace with:

  3. Search for (lines 1988 and 1989):

    if ( my $ts =
        ( $type eq 'page' ) ? $obj->modified_on : $obj->authored_on )

    Replace with:

    if ( my $ts = $obj->authored_on )

Once these edits have been made, login to Movable Type and view the Manage Pages screen. All pages will be listed by created_on date.

That’s it!

Previously, I wrote about how to add Edit Links to Entry and Page templates.

This guide uses the mt_user cookie set when logging into Movable Type to condition content (links to screens in MT) on entries and pages published by Movable Type.

Also provides an option to use a non-MT cookie to do the same thing.

Ordering Categories (a hack)


One feature I’d like to add is the ability to order categories via some drag-n-drop method in Movable Type and then have the ability to specify the sort order manually via a sort_by template tag modifier like this:

<mt:Categories sort_by="manual">
    <!-- category code here -->

Or just make this the default behavior!

Until then, here’s a hack to sort by a user-order specified.

  1. Go to the Edit Categories screen.
  2. Using the “open link in new tab” option (right-click or command-click), click each category to open them in new tabs in the order that you want them in.
  3. Just before the text of the label, add an html comment and place a number in the comment. Make each html comment identical to ensure sorting works properly. Because the number is in an HTML comment, it won’t be displayed on your site, but the sorting will be correct!