Hack Movable Type App to list pages by created date

| 1 Comment

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

Entries:

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

Pages:

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

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

$MT_HOME/tmpl/cms/include/entry_table.tmpl

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>
    

$MT_HOME/lib/MT/CMS/Entry.pm

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):

    $entry->modified_on($ts);
    

    Replace with:

    $entry->authored_on($ts);
    
  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!

1 Comment

I just don’t know why my MT powered post are all scattered and really annoying. I am so thankful that I find this site that will really help me a lot. I will now configure my personal blog with the use of this code. I just hope that it works fine. By the way thanks for sharing the codes and the explanation. You are really great.

Leave a comment