{"id":250,"date":"2003-06-14T15:11:50-04:00","date_gmt":"2003-06-14T23:11:50+00:00","guid":{"rendered":"http:\/\/peterjanes.ca\/wordpress\/?p=250"},"modified":"2003-06-14T15:11:50-04:00","modified_gmt":"2003-06-14T23:11:50+00:00","slug":"movable-type-trick","status":"publish","type":"post","link":"https:\/\/peterjanes.ca\/blog\/2003\/06\/14\/movable-type-trick\/","title":{"rendered":"Movable Type&nbsp;trick"},"content":{"rendered":"<div class='e-content'><p>One of the (many!) nice things about <a href=\"http:\/\/www.movabletype.org\/\">Movable Type<\/a> is its customizability.  I didn&#8217;t realize just how far that extended until today.<\/p>\n\n<p>I&#8217;d read previously in the MT UI that <q>you can customize the output path for the archive files using Archive File Templates<\/q>, and I&#8217;ve done so to provide more usable URLs based on the page title since just after I started <a href=\"\/\">Petroglyphs<\/a>.  Recently, I wanted to do a similar thing for another site, except that not all of the entries are guaranteed to have titles.  Using my existing template, <code>&lt;$MTArchiveDate format=&quot;%Y\/%m\/%d&quot;$&gt;\/&lt;$MTEntryTitle dirify=\"1\"$&gt;.html<\/code>, didn&#8217;t work because I wound up generating filenames like <samp>.html<\/samp>, but for a number of reasons (not least of all <a href=\"http:\/\/www.w3.org\/Provider\/Style\/URI.html\" title=\"Cool URIs Don't Change\">this<\/a>) I didn&#8217;t want to add arbitrary characters or otherwise change the template.<\/p>\n\n<p>MT plugins to the rescue.  <a href=\"http:\/\/bradchoate.com\/\"><cite>Brad Choate<\/cite><\/a> has <a href=\"http:\/\/www.bradchoate.com\/past\/cat_movable_type.php\">written prolificly<\/a> on MT, and developed a number of useful plugins that I&#8217;ve dutifully installed.  The one that solved this problem, and made me appreciate MT more, is his <a href=\"http:\/\/bradchoate.com\/past\/000657.php\"><cite>MTIfEmpty<\/cite><\/a>.  Basically what this does is check an expression&#8211;most often an MT tag itself&#8211;to see if it&#8217;s empty; the plugin also includes <cite>MTIfNotEmpty<\/cite> to do the opposite.<\/p>\n\n<p>As it turns out, MT lets you use tags defined by plugins almost anywhere, not just in your page templates.  (The one exception I&#8217;ve found is that you can&#8217;t use any tags directly in your entries&#8211;even built-in ones&#8211;although I&#8217;ve found a workaround for that too using another of Brad&#8217;s tools.)  The practical upshot of this is that <em>you can use plugins in your filename templates<\/em>.<\/p>\n\n<p>So without further ado, I present the template above, modified to use the filename <cite>untitled<\/cite> when appropriate: <code>&lt;$MTArchiveDate format=&quot;%Y\/%m\/%d&quot;$&gt;\/&lt;MTIfEmpty expr=&quot;[MTEntryTitle dirify=&apos;1&apos;]&quot;&gt;untitled&lt;\/MTIfEmpty&gt;&lt;$MTEntryTitle dirify=\"1\"$&gt;.html<\/code><\/p><\/div><div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"One of the (many!) nice things about Movable Type is its customizability. I didn&#8217;t realize just how far that extended until today. I&#8217;d read previously in the MT UI that you can customize the output path for the archive files using Archive File Templates, and I&#8217;ve done so to provide more usable URLs based on&hellip;","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"venue_id":0},"categories":[3],"tags":[],"kind":false,"_links":{"self":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts\/250"}],"collection":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/comments?post=250"}],"version-history":[{"count":0,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/posts\/250\/revisions"}],"wp:attachment":[{"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/media?parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/categories?post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterjanes.ca\/blog\/wp-json\/wp\/v2\/tags?post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}