Lastn Entries By modified_on

I just killed most of a perfectly good Sunday afternoon trying to solve this stupid problem in Movable Type, and now that I've got it I had better preserve it for posterity.

All I wanted to do on my home page was display one entry excerpt from my 'Photo' category, selected by most recent date modified as opposed to most recent date authored; this is because I have a big backlog of old photos that I would like to appear on the home page as I add them, regardless of their original date (which I plan to preserve as the entry date.)

The problem is that the only attribute of the <MTEntries> tag that lets you limit the number of entries displayed is lastn, and lastn is only good for displaying entries based on entry_created_on in descending order.

I haven't had many gripes about MT so far, but that's a fairly major one now that I've come across that particular limitation.

The workaround is to use Brad Choate's, SQL Plugin, with this query:

SELECT entry_id FROM mt_entry LEFT JOIN mt_placement ON placement_entry_id = entry_id WHERE entry_blog_id = x AND entry_status = 2 AND placement_category_id = y ORDER BY entry_modified_on DESC LIMIT z

Where x, y, and z are the desired blog id, category id, and number of entries respectively. An entry status of '2' restricts the query to show only entries set to 'Publish'.

I installed the plugin and worked out the above query, only to get an error from the DBI library. As usual, Google was my friend, and pointed me to Mike James' post, Solution to MT SQL plugin DBI error.

The problem is with an older version of the Perl DBI module. The solution: Assuming you have a shell account but not root access to your web server, download the latest DBI module from CPAN, build and install it in your home directory, and tweak MT to use your version instead of the system version. This last is accomplished by adding the line

use lib qw(/home/your_user_name/lib/i386-linux);

above the use DBI; statement in /path/to/mt/lib/MT/ObjectDriver/DBI.pm. See the actual post for more specifics.

I do love Movable Type, but the lack of a more generic, SQL-like 'limit' attribute in the <MTEntries> tag is kind of puzzling.

2 comments

 
Gwen Harlow resources wrote 10 years 31 weeks ago

Sort by most recent Sort by

Sort by most recent

Sort by recent using MTSQL

 
doesntsuck.com wrote 10 years 26 weeks ago

yeah, ok So today I decided

yeah, ok

So today I decided I'd like to have a list of the books I've read recently (besides the ones I'm reading RIGHT NOW) in my sidebar. It's there now, but only because I (and several other people) are awesome. Here's...

Please register or login to post a comment.
Syndicate content

Twitter

  • Nothing says "this crappy joke that's been forwarded 27 times is not nearly as funny as the subject line says" like Comic Sans. #fb 4 years 35 weeks ago
  • Ah, southwestern New Hampshire, where it's hard to tell whether or not a guy's mullet is ironic. #fb 4 years 37 weeks ago
  • Pancake making hack: put the syrup in The oven at 200F along w/pancakes to keep everything nice and hot. #fb 4 years 37 weeks ago
  • Just finished cooking one of those meals that somehow completely destroys the kitchen. I'll be more organized next time. #fb 4 years 37 weeks ago
  • I wish the TSA would get on with it and just ban passengers from flights altogether. That will make us all safe. 4 years 37 weeks ago

Older

Contact

Andy Chase
(978) 297-6402
andychase [at] gmail.com
GPG/PGP Public Key