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 22 weeks ago

Sort by most recent Sort by

Sort by most recent

Sort by recent using MTSQL

 
doesntsuck.com wrote 10 years 18 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

  • @ernestkoe basically this script with duration set to 25 minutes, and limited to tracks 3 minutes & under: http://t.co/bupgfBH 2 years 46 weeks ago
  • @ernestkoe has got me digging Pomodoro. I modified one of my iTunes applescripts to make me nice 25 minute playlists. 2 years 46 weeks ago
  • @tommysalami I'm planning to tear it down and make a static site with links to activity streams elsewhere; it's hardly a destination. 2 years 47 weeks ago
  • @tommysalami I think you may be the one person on the internets subscribed to my RSS feed. That was the first thing I've posted all year! 2 years 47 weeks ago
  • Possibly the most simultaneously hilarious and disturbing video you'll watch today. http://sgp.cm/6f9b89 2 years 49 weeks ago

Older

Contact

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