<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>MovableType Tips</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/" />
    <link rel="self" type="application/atom+xml" href="http://MTTips.com/atom.xml" />
    <id>tag:MTTips.com,2008-10-08://5</id>
    <updated>2008-10-08T20:50:58Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>

<entry>
    <title>Leverage Your RSS Feed</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/leverage_your_rss_feed.html" />
    <id>tag:www.MTTips.com,2008://5.1747</id>

    <published>2008-05-15T21:41:50Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary><![CDATA[Chances are your RSS or Atom feed template has a section that includes likes like these: &lt;MTEntries lastn="15"&gt; &lt;item&gt; &lt;title&gt;&lt;$MTEntryTitle remove_html="1" encode_xml="1"$&gt;&lt;/title&gt; &lt;description&gt;&lt;$MTEntryBody encode_xml="1"$&gt;&lt;/description&gt; &lt;link&gt;&lt;$MTEntryPermalink encode_xml="1"$&gt;&lt;/link&gt; &lt;pubDate&gt;&lt;$MTEntryDate format_name="rfc822"$&gt;&lt;/pubDate&gt; &lt;/item&gt; &lt;/MTEntries&gt; If so, you're missing out on something very, very powerful....]]></summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>Chances are your RSS or Atom feed template has a section that
includes likes like these:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;MTEntries lastn="15"&gt;<br />
&lt;item&gt;<br />
&lt;title&gt;&lt;$MTEntryTitle remove_html="1"
encode_xml="1"$&gt;&lt;/title&gt;<br />
&lt;description&gt;&lt;$MTEntryBody
encode_xml="1"$&gt;&lt;/description&gt;<br />
&lt;link&gt;&lt;$MTEntryPermalink
encode_xml="1"$&gt;&lt;/link&gt;<br />
&lt;pubDate&gt;&lt;$MTEntryDate
format_name="rfc822"$&gt;&lt;/pubDate&gt;<br />
&lt;/item&gt;<br />
&lt;/MTEntries&gt;</blockquote>
<p>If so, you're missing out on something very, very powerful.</p>]]>
        <![CDATA[<p>Let's make two assumptions:</p>
<ul>
<li>
<p>Your feed will be republished</p>
</li>
<li>
<p>You don't know where your feed will be republished</p>
</li>
</ul>
<p>You have an opportunity to "brand" each entry you publish in your
RSS feed with additional, static content that you control. When your
RSS feed is republished, that content will be included.</p>
<p>The magic happens here:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;description&gt;<span style="color:red">&lt;$MTEntryBody
encode_xml="1"$&gt;</span>&lt;/description&gt;<br /></blockquote>
<p>Why include only the body?</p>
<p>Here's the equivalent segment from the <a href="http://ask-leo.com"
target="_blank">Ask Leo!</a> RSS feed:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;description&gt;<br />
&lt;$MTEntryBody encode_xml="1"$&gt;<br />
&lt;![CDATA[&lt;p&gt;Continue reading<br />
&lt;a href="&lt;$MTEntryLink encode_xml="1"$&gt;"&gt;&lt;$MTEntryTitle
remove_html="1" encode_xml="1"$&gt;&lt;/a&gt;&lt;br/&gt;<br />
&lt;a href="http://ask-leo.com"&gt;Tech Questions?&lt;/a&gt;<br />
&lt;a href="http://ask-leo.com"&gt;Get Answers!&lt;/a&gt; -<br />
&lt;a href="http://ask-leo.com"&gt;Ask Leo!&lt;/a&gt; ... by Leo
Notenboom&lt;br/&gt;<br />
&lt;a href="http://newsletter.ask-leo.com"&gt;Leo's Answers
Newsletter&lt;/a&gt; -<br />
&lt;a href="http://ask-leo.com"&gt;Ask Leo!&lt;/a&gt; in your inbox
every week.<br />
&lt;/p&gt;]]&gt;&lt;/description&gt;</blockquote>
<p>Examine that carefully. All I've done is added to the template some
static text - encoded for XML - that appears at the bottom of every
item in my RSS feed that adds:</p>
<ul>
<li>
<p>An explicit "Continue Reading ..." link (not all news readers make
this option obvious).</p>
</li>
<li>
<p>Branding and keyword targeted links back to my site (guess who's
currently #1 for "Tech Questions" and #4 for "Get Answers"?)</p>
</li>
<li>
<p>An engagement link, encouraging newsletter signups.</p>
</li>
</ul>
<p>So, in the RSS feed entry for <a href=
"http://ask-leo.com/why_am_i_not_getting_some_emails_in_my_msn_live_hotmail_account.html"
target="_blank">Why am I not getting some emails in my MSN Live Hotmail
account?</a>, we get the entry body (which in my case is a "tease" to
read the rest of the article) followed by this:</p>
<blockquote>
<p>Continue reading <a href=
"http://ask-leo.com/why_am_i_not_getting_some_emails_in_my_msn_live_hotmail_account.html">
Why am I not getting some emails i n my MSN Live Hotmail
account?</a><br />
<a href="http://ask-leo.com">Tech Questions?</a> <a href=
"http://ask-leo.com">Get Answers!</a> - <a href=
"http://ask-leo.com">Ask Leo!</a> ... by Leo Notenboom<br />
<a href="http://newsletter.ask-leo.com">Leo's Answers Newsletter</a> -
<a href="http://ask-leo.com">Ask Leo!</a> in your inbox every week.</p>
</blockquote>
<p>As you might imagine, while I've used only some simple static text
and links, which I believe are appropriate and inoffensive to my target
audience, the gates are actually wide open for anything that most feed
readers might display.</p>
<p>Regardless, it's an opportunity for some simple, easy and quick
content distribution.</p>]]>
    </content>
</entry>

<entry>
    <title>Place Ads Precisely with OpenAds</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/place_ads_precisely_with_openads.html" />
    <id>tag:www.MTTips.com,2007://5.1746</id>

    <published>2007-09-29T22:03:23Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>OpenAds, formerly known as PhpAds, is an ad management server that many people are using to display and control ad blocks on their web sites. My site Ask Leo! used OpenAds to serve up ads, including both Google&apos;s Adsense as...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tricks" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p><a href="/d-openads" target="_blank">OpenAds</a>, formerly known as PhpAds,
is an ad management server that many people are using to display and control ad
blocks on their web sites. My site <a href="http://ask-leo.com">Ask Leo!</a>
used OpenAds to serve up ads, including both Google's Adsense as well as
<a href="http://ask-leo.com/advertising_info.html#website">direct purchase
advertising</a>.</p>
<p>The "problem" is that OpenAds doesn't natively support the level of ad
placement that I'm looking for. However things like that don't always stop me.
This article describes the approach I've taken using OpenAds to place ads in my
MovableType generated pages:</p>
<ul>
<li>in specific articles</li>
<li>on specific pre-defined positions on a page</li>
<li>any combination of those two</li>
<li>in any specific category</li>
<li>site wide</li>
</ul>
<p>All while maintaining <em>most</em> of OpenAds other features including
weighted distribution of ad content.</p>
<p>Now, I do have to throw out a few caveats:</p>
<ul>
<li>As I write this I'm running OpenAds 2.0.11. Naturally later versions might
add features and functionality that make my efforts redundant.</li>
<li>I'm going to assume you have at least a basic understanding of OpenAds.
It's non trivial, and documenting it is well beyond the scope of this site, and
for that matter, my abilities.</li>
<li>My approach might be stupid. Someone more familiar with OpenAds might well
say "you should do it this way" and define something much more elegant. Fair
enough. My approach works, though.</li>
</ul>
<p>With all that butt-covering out of the way, let's dive in.</p>]]>
        <![CDATA[<p>I don't use Zones.</p>
<p>As I understand it, Zones are OpenAds way of defining areas that ads can
appear in. You might define the "above the fold" area of a page is a particular
zone, and then later assign ads to run in particular zones.</p>
<p>I couldn't figure out zones.</p>
<p>As far as I could tell, defining a new zone, for say, each individual
article or class of article or position on a page, or more importantly,
arbitrary combinations of those was beyond me. I couldn't see it as being
possible.</p>
<p>So I did it my way.</p>
<p style="text-align: center">&bull;</p>
<p>I've defined several conceptual ad block positions. For example what I refer
to as "adblock #1" is my prime position, on the left "above the fold" block on
every individual entry archive page. "adblock #3" is the newsletter subscribe
box you see further down the page, also on every individual archive page. There
are others, but I'll focus on those for purposes of example.</p>
<p>And as you know, in MovableType, each entry is given it's own ID number, and
can be assigned one or more categories, each with its own label.</p>
<p>Given all that information we have enough to define every ad block on every
page or within every category uniquely. The problem is getting that information
to OpenAds in a way that will allow it to select ads based on somehow using
those as criteria.</p>
<p>Buried deep in the OpenAds documentation is the concept of selection
strings, advanced selection strings, and keywords.</p>
<p>The concept is simple: using the ad blocks I've defined plus the entry and
category IDs MovableType generates, we define a set of keywords and use them in
selection strings that are automatically generated when the pages are built by
MovableType. Then by assigning the appropriate keywords to the ad inventory
itself we can control with precision exactly what ad gets placed where.</p>
<p>This is best explained with examples.</p>
<p style="text-align: center">&bull;</p>
<p>Here's the line from the individual entry archive template on Ask Leo! (it's
actually all on one line, but formatted here for readability):</p>
<pre style="margin-left: 30px">
&lt;!--#include VIRTUAL="adblock.php?
  block=1&amp;
  entryid=&lt;$MTEntryID$&gt;&amp;
  catid=&lt;MTEntryCategories glue="|"&gt;
          &lt;MTParentCategories glue="|"&gt;
            &lt;$MTCategoryLabel dirify="1" $&gt;
          &lt;/MTParentCategories&gt;
        &lt;/MTEntryCategories&gt;
  " --&gt;      
</pre>
<p>Adblock.php is a small php script I'll discuss in a moment. What's of
interest first are the parameters that it's being passed:</p>
<ul>
<li>
<p><strong>block</strong> is the adblock id number I dreamed up. As I mentioned
earlier, ad block #1 is the upper left above-the-fold ad block, and that is
where this line is positioned in the individual entry template.</p>
</li>
<li>
<p><strong>entryid</strong> is exactly that: the entry ID number assigned to
the current entry as defined by MovableType.</p>
</li>
<li>
<p><strong>catid</strong> is a <em>list</em> of the dirified labels for all the
categories and subcategories that the current article might be assigned to.</p>
</li>
</ul>
<p>Using the article <a href="http://ask-leo.com/who_is_leo.html" target=
"_blank">Who is Leo?</a> as an example, that line is expanded when the page is
built into this:</p>
<pre style="margin-left: 30px">
&lt;!--#include VIRTUAL="adblock.php?block=1&amp;entryid=484&amp;catid=administration" --&gt;
</pre>
<p>In English, that means this line is referring to ad block #1 on the page for
entry ID #484 in the category "administration".</p>
<p>However if you view source on that page, that's not at all what you'll see.
Adblock.php's job is to <em>generate</em> the Javascript used by OpenAds to
place an HTML ad. In the current example, what you'll adblock.php generate is
this:</p>
<pre style="margin-left: 30px">
&lt;div class="adblock1"&gt;
&lt;script language='JavaScript' type='text/javascript' src='http://ads.pugetsoundsoftware.com/adx.js'&gt;&lt;/script&gt;
&lt;script language='JavaScript' type='text/javascript'&gt;
&lt;!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
   
   document.write ("&lt;" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://ads.pugetsoundsoftware.com/adjs.php?n=" + phpAds_random + "&amp;amp;what=");
   document.write ("adblock1,_entryid484|adblock1,_administration|adblock1def");
   document.write ("&amp;amp;exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&amp;amp;referer=" + escape(document.referrer));
   document.write ("'&gt;&lt;" + "/script&gt;");
//--&gt;
&lt;/script&gt;
&lt;/div&gt;
</pre>
<p>You'll notice that, aside from the &lt;div&gt; I've placed around it for my
own CSS needs, this is very similar to the JavaScript code that OpenAds offers
you to copy/paste if you use their standard ad placement mechanisms. If you
look closely, though, you'll see that the parameters passed to adblock.php have
made it into the JavaScript in what is probably an unfamiliar fragment:</p>
<pre style="margin-left: 30px">
   "adblock1,_entryid484|adblock1,_administration|adblock1def"
</pre>
<p><em>This</em> is an advanced selection string.</p>
<p>Again, I won't go into the details of selection strings, but to translate
this one into English, it says, effectively:</p>
<ul>
<li>
<p>select ads with <em>both</em> keywords adblock1 <em>and</em> entryid484</p>
</li>
<li>
<p>if there aren't any of those, then select ads with <em>both</em> keywords
adblock1 <em>and</em> administration</p>
</li>
<li>
<p>if there aren't any of those, then select ads with the keyword
<em>adblock1def</em></p>
</li>
</ul>
<p>Now, go have a look at the page in OpenAds where you define or modify an
HTML banner ad. You'll notice a little field labeled "Keywords".</p>
<p>This is the point at which you should be excited.</p>
<p>If I want an ad to appear on <em>only</em> in this position and only on this
page, then in the ad inventory I assign it the keywords "adblock1" and
"entryid484". (Multiple keywords are space separated in OpenAds, so what I'd
enter would be "adblock1 entryid484".)</p>
<p>If I want an add to appear in this position and on every page in the
category "administration", I assign it the keywords "adblock1" and
"administration".</p>
<p>If I want an add to appear site-wide in this ad block position I assign it
<em>only</em> the keyword "adblock1".</p>
<p>And finally, I make sure to define an adblock that's to be used if all else
fails, and assign that the keyword "adblock1def" for "ad block 1, default". If
no other ads are configured to be in this particular spot on this particular
page, then it's adblock1def that is show. In my case, adblock1def contains my
Google Adsense code.</p>
<p>That's really all there is too it.</p>
<p style="text-align: center">&bull;</p>
<p><strong>Summary</strong></p>
<ol>
<li>
<p>Come up with a numbering scheme that identifies your ad block positions.</p>
</li>
<li>
<p>Download and modify adblock.php to reference your own installation of the
OpenAds ad server.</p>
</li>
<li>
<p>Upload adblock.php to your site</p>
</li>
<li>
<p>Modify your MovableType templates to reference adblock.php where you want
adblocks to be placed. Make sure to pass the appropriate block ID that you
defined in step 1.</p>
</li>
<li>
<p>Create default HTML ads in OpenAds referencing "adblockXdef" for each
adblock that you've defined.</p>
</li>
<li>
<p>Start creating HTML ads to override those defaults using keywords as
appropriate.</p>
</li>
</ol>
<p>And finally, <a href="adblock.zip">download adblock.php</a> (in zip form).
<strong>Caveat/disclaimer</strong>: this code is presented for your use without
warranty or guarantee of any sort. For all I know it'll reformat your server,
crash your car, give your cat fleas and eat your homework. I don't
<em>think</em> it'll do anything of the sort, but I don't guarantee that it
won't. By using it, you're assuming all responsibility for whatever it might
do.</p>
<p>Oh, and you're free to use it wherever you like. A link back to either
http://www.MTTips.com or http://Ask-Leo.com would be appreciated.</p>]]>
    </content>
</entry>

<entry>
    <title>Tolerate Broken URLs</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/tolerate_broken_urls.html" />
    <id>tag:www.MTTips.com,2007://5.1745</id>

    <published>2007-05-18T23:05:08Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>If you use meaningful page names on your site, you&apos;ll often end up with URLs that are quite long. For example out on Ask Leo! you&apos;ll find an article entitled What&apos;s the difference between Windows Live Messenger, Windows Messenger, MSN...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tricks" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>If you <a href="http://mttips.com/use_meaningful_page_names.html">use meaningful page names</a>
on your site, you'll often end up with URLs that are quite long. For example
out on Ask Leo! you'll find an article
entitled <a href="http://ask-leo.com/whats_the_difference_between_windows_live_messenger_windows_messenger_msn_messenger_and_windows_messenger_service.html" target="_blank">What's the difference between Windows Live Messenger, Windows Messenger, MSN Messenger and Windows Messenger Service?</a>.
If you look at the resulting URL, it's <i>very</i> long. So long, in fact, that I need
to chop it down to show it to you here:</p>
<blockquote>
http://ask-leo.com/whats_the_difference_between_windows ... vice.html
</blockquote>
<p>More commonly you'll recognize this situation in email programs when you try to email someone
a long link:</p>
<blockquote>
<a href="http://ask-leo.com/whats_the_difference_between_windows_live_messenger_" target="_blank">http://ask-leo.com/whats_the_difference_between_windows_live_messenger_</a><br />
windows_messenger_msn_messenger_and_windows_messenger_service.html
</blockquote>
<p>As you see above, email programs see the "http://" on the first line and automatically
treat the rest of it as a link. But since the line is too long to fit on the screen,
they break it into two, and then don't include the second half in that link.
If you click on the highlighted link you get an error from the destination
site, since you didn't provide the full page URL.</p>
<p>And yet, if you click on that partial link above for Ask Leo!, you'll get to the intended page
anyway.</p>
<p>Ask Leo! tolerates broken URLs. Here's how I do it.</p>]]>
        <![CDATA[<p>The steps are simple:</p>
<ul>
<li><p>I have a custom 404 error handling page written in PHP called "404resolver.php".</p></li>
<li><p>When a page is about to be reported as "not found", the web server displays this page instead, passing in the name of the original page that was requested.</p></li>
<li><p>404resolver.php <i>examines the files in the directory of the web site</i>, looking for ".html" files that begin with what was passed in as the original request:</p>
<ul>
<li><p>If it finds none, it reports a "page not found" like any 404 handler would.</p></li>
<li><p>If it finds exactly one, it performs an immediate 301 redirect to that page.</p></li>
<li><p>If it finds more than one, it displays a list and asks the visitor to make a choice.</p></li>
</p></li>
</ul>
</ul>
<p>Let's look at those three scenarios in practice before we look at the code.</p>
<p><b>Page Not Found</b>: <a href="http://ask-leo.com/whats_the_difference_between_windows_live_messenger_and_mttips" target="_blank">http://ask-leo.com/whats_the_difference_between_windows_live_messenger_and_mttips</a>: this page does not exist, and will get you a "page not found" error. Try it.</p>
<p><b>One match</b>: <a href="http://ask-leo.com/whats_the_difference_between_windows_live_messenger_" target="_blank">http://ask-leo.com/whats_the_difference_between_windows_live_messenger_</a>: this page doesn't exist, but there's only one page that begins with exactly that URL. Since there's only one possible match, you're redirected to it as if you had gone there to start with.</p>
<p><b>Many matches</b>: <a href="http://ask-leo.com/whats_the_difference_between_" target="_blank">http://ask-leo.com/whats_the_difference_between_</a>: this page doesn't exist, and there are several pages that start with that URL fragment. Since we know there are options, but we can't know which one was intended, we present a list and let the visitor choose.</p>
<p style="text-align: center">&bull;</p>
<p><b>The Code</b></p>
<p>I'm only going to present snippets here. The full code is
available below for download.</p>
<p>The real brains of the operation are in this code sequence:</p>
<pre>
  $szRequestedPage = $_SERVER['REQUEST_URI'];
  $cRequestedLength = strlen($szRequestedPage);

  $dir = $_SERVER['DOCUMENT_ROOT'];
  if ($dh = opendir($dir))
    {
    while (($file = readdir($dh)) !== false) 
      { // build array of possible matches
      $file = strtolower($file);
      if (0 == strcmp (".html", substr($file, -5)))
        { // limit to .html files only
        if (0 == strncmp (strtolower ($szRequestedPage), "/" . $file, $cRequestedLength))
          { // possible match
          $rgMatchingPages[] = $file;
          }
        }
      }
    closedir($dh);
    }
</pre>
<p>This code takes the originally requested page or "REQUEST_URI", and compares it against every file in the
root of the website's document root on the server. Every page that begins with exact same
string as was originally requested is added to a list.</p>
<p>When that code is done, we have a list of pages which <i>might</i> be the desired page.</p>
<p>Next we act based on how many potential matches were found.</p>
<pre>
  if (0 >= count($rgMatchingPages))
    { // none found. Redirect to the "real" 404 page
    header ("HTTP/1.1: 301 OK");
    header ("Location: /notfound.html");
    exit(0);
    }
    
  if (1 == count($rgMatchingPages))
    { // only one match. Redirect to it, we're done.
    header ("HTTP/1.1: 301 OK");
    header ("Location: /" . $rgMatchingPages[0]);
    exit(0);
    }
</pre>
<p>As you can see if there's no match found, we redirect to the "real" page not found page. And if there's
only one possible match found, we simply redirect to that page.</p>
<p>If more than one potential match 
we're going to display something, so we start outputting actual HTML:</p>
<pre>
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
 &lt;head&gt;
  &lt;link rel="stylesheet" href="/al.css" type="text/css" /&gt;
  &lt;meta http-equiv="Content-Language" content="en-us" /&gt;
  ...
</pre>
<p>The HTML being output is really whatever is necessary to display a page of your own
design. Naturally mine outputs the "look and feel" of Ask Leo!.</p>
<p>However, within that page is an important sequence of code:</p>
<pre>
     &lt;ul&gt;
&lt;?php
      // NOTE: this PHP loop outputs the possible matches. Replace (or not) the
      // HTML code within the "echo" statement as you see fit. Take care to use
      // single quotes, or to precede each embedded double quote with a backslash.
      //
      sort ($rgMatchingPages);
      reset ($rgMatchingPages);
      foreach ($rgMatchingPages as $page)
        {
        echo "&lt;li&gt;&lt;a href=\"$page\"&gt;$page&lt;/a&gt;&lt;/li&gt;\n";
        }
?&gt;
     &lt;/ul&gt;
</pre>
<p>This code outputs a bulleted list, in sorted order, of the possible matches to the
pages requested. Each is output as a link for the visitor to make his or her choice and
click on.</p>
<p>That's really all there is to it.</p>
<p>A couple of caveats, of course...</p>
<ol>
<li><p>Even though this is MTTips.com, there's actually nothing MT-specific about this
solution. Any site that uses static HTML pages and can run PHP can use this solution.
Naturally the concepts can certainly be extended to cover other technologies. (I've
heard of at least one WordPress-based solution as well.)</p></li>
<li><p>In that same vein, this solution assumes all pages appear in the root of your
site. Additional logic can certainly be added to handle other site organizations. The
basic idea here is simple: use the page name that the user <i>tried</i> to get to as
some kind of clue for what they were actually looking for. If you can, give them that
without delay.</p></li>
</ol>
<p>The full 404resolver.php as used on Ask Leo! can be <a href="404resolver.zip">downloaded here</a>.</p>]]>
    </content>
</entry>

<entry>
    <title>Leaving Breadcrumbs in Movable Type</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/leaving_breadcrumbs_in_movable_type.html" />
    <id>tag:www.MTTips.com,2007://5.1744</id>

    <published>2007-01-20T00:15:27Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>Breadcrumbs are staple (pardon the pun) of many web sites. You&apos;ve seen them, they&apos;re the line typically near the top of an article page that shows you where in the tree of semi-organized information that article resides. Something like: News...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tricks" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>Breadcrumbs are staple (pardon the pun) of many web sites. You've seen them,
they're the line typically near the top of an article page that shows you where
in the tree of semi-organized information that article resides. Something
like:</p>
<blockquote>
<p>News Home : World : National : Local : Seattle : Space Needle on Fire</p>
</blockquote>
<p>Each of those encompasses everything to its right, and each would be a link
to a summary page for that level of topic. The last might be the actual page
you're on.</p>
<p>If you've used Movable Type for any length of time, you might be thinking
something about categories, sub categories and the like.</p>
<p>As was I, when a friend prodded me with "If you come up with an MT hack for
that, please post it."</p>
<p>I hate a challenge that I can't resist if I'm already overbooked - particularly
for something I want myself. :-)</p>]]>
        <![CDATA[<p><a href="http://ask-leo.com" target="_blank">Ask Leo!</a> now has
breadcrumbs. I still have work to do, though, as I'll explain in a moment.</p>
<p>First, here's the template snippet that I've placed in my Individual Entry
template:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;p&gt;<br />
&nbsp;&lt;MTEntryCategories&gt;<br />
&nbsp;&nbsp;&lt;a href="/"&gt;Home&lt;/a&gt; &amp;raquo;<br />
&nbsp;&nbsp;&lt;MTParentCategories glue = "&amp;raquo; "&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;a href="&lt;$MTCategoryArchiveLink$&gt;"
title="&lt;$MTCategoryDescription$&gt;"&gt;&lt;$MTCategoryLabel$&gt;&lt;/a&gt;<br />
&nbsp;&nbsp;&lt;/MTParentCategories&gt;<br />
&nbsp;&nbsp;&lt;br /&gt;<br />
&nbsp;&lt;/MTEntryCategories&gt;<br />
&lt;/p&gt;</blockquote>
<p>That's it. That generates a breadcrumb line based on your category
assignment, and the arrangement of the category and subcategory hierarchy that
you've created.</p>
<p>Here's an example on <a href="http://ask-leo.com" target="_blank">Ask Leo!</a>: <a href=
"http://ask-leo.com/how_do_i_determine_the_capabilities_of_my_wireless_network_adapter.html"
target="_blank">How do I determine the capabilities of my wireless network
adapter?</a></p>
<p>So, a couple of important "how too" points:</p>
<ul>
<li>
<p>It's important that you organize your categories and subcategories well.
You're looking to create a sensible, hierarchical tree of categories. In my
example, "Wireless Networking" is a subcategory underneath "Networking". (And herein lies my work
for <a href="http://ask-leo.com" target="_blank">Ask Leo!</a> - I need to retrofit a meaningful
hierarchy for my categories.)</p>
</p>
</li>
<li>
<p>In general you want to assign each post to a single category, and that would
typically be a leaf from that hierarchy tree. You can assign a intermediate or
node value instead, if you like, but I'm assuming that leaves will give your
readers the clearest understanding of your organization. In my example the post
is assigned a category of "Wireless Networking" - that's all.</p>
</li>
</ul>
<p>That's it. The template code above prints the path down your hierarchy to
that particular category leaf.</p>
<p style="text-align: center">&bull;</p>
<p>And now, a word about multiple categories.</p>
<p>MovableType allows you assign multiple categories to entries. In such a
case, the code above will print a separate breadcrumb line for each category
you've assigned to a post. Typically if you do this, you'll want the categories
to be leaves on different branches of the hierarchy tree. For example, it'd
look kinda silly to assign both "Networking" and "Wireless Networking" when the
later us a branch off the former. The breadcrumb lines would look like
this:</p>
<blockquote>
<p>Home &raquo; Networking<br />
Home &raquo; Networking &raquo; Wireless Networking</p>
</blockquote>
<p>That not only looks kinda silly, but is also redundant.</p>
<p>On the other hand, if I had a separate branch in my category hierarchy that
this article also applied to, it might make sense to assign it a second
category within that branch. For example:</p>
<blockquote>
<p>Home &raquo; Hardware &raquo; Network Adapters &raquo; Configuration<br />
Home &raquo; Networking &raquo; Wireless Networking</p>
</blockquote>
<p>Not only is it not redundant, but shows your visitor that the post might
very well have two larger contexts of interest.</p>
<p>References:</p>
<ul>
<li>
<p>I got a boost from the information here: <a href=
"http://www.rayners.org/2003/08/subcategories.php" target="_blank">David
Raynes: Subcategories</a>. That was written before MovableType actually
supported any of this, but includes a plugin for pre-3.x MT that I believe
enables most of what I've just described.</p>
</li>
</ul>]]>
    </content>
</entry>

<entry>
    <title>Use Meaningful Page Names</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/use_meaningful_page_names.html" />
    <id>tag:www.MTTips.com,2006://5.1743</id>

    <published>2006-12-14T19:22:37Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>It&apos;s a fairly common search engine technique to use &quot;meaningful&quot; page names in your URL. &quot;apples.html&quot; is seen by the search engines as more likely to be about apples than, say, &quot;000023.html&quot;. Similarly, pages that are at the root of...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>It's a fairly common search engine technique to use "meaningful" page names
in your URL. "apples.html" is seen by the search engines as more likely to be
about apples than, say, "000023.html". Similarly, pages that are at the root of
your site may be considered more "important" than those in subdirectories.</p>
<p>My approach at <a href="http://ask-leo.com" target="_blank">Ask Leo!</a> is
to use the article title as the basis for the URL and to place it in the root.
Fortunately, MovableType makes both of the steps easy.</p>]]>
        <![CDATA[<p>First we'll change the location of all the individual archives to be in the
root. That's part of the Publishing Settings page in your Weblog Configuration
(formerly the Core Setup page in versions prior to 3.2):</p>
<p style="text-align: center"><img src="/images/publishingpaths.png" alt=
"Publish Paths Configuration" title="Publish Paths Configuration" style=
"border: 1px solid black" /></p>
<p>Two changes typically need to be made to the default settings:</p>
<ol>
<li>
<p>The <strong>Archive Root</strong> (the <strong>Local Archive Path</strong>
pre-3.2) needs to be set to the same value as the <strong>Site Root</strong>
(<strong>Local Site Path</strong>), and</p>
</li>
<li>
<p>The <strong>Archive URL</strong> should be set to the same value as the
<strong>Site URL</strong>. Note that the URLs end with a slash while the paths
do not.</p>
</li>
</ol>
<p>Now that all the pages are in the same place, we need to change the
filenames that MovableType uses to generate them. Further down the Publishing
Settings page in your Weblog Config you'll find a section labeled
<strong>Archive Mapping</strong> (or simply the Archive Files page in pre 3.2
versions of MT).</p>
<p>The "Archive File Path" (or "Archive File Template" in pre-3.2) is more
correctly thought of as the "archive filename template". Using templating
variables, here you can control the filenames that MT will create.</p>
<p style="text-align: center"><img src="/images/archivemapping.png" alt=
"Archive Mapping Settings" title="Archive Mapping Settings" style=
"border: 1px solid black" /></p>
<p>Here you can see that that Individual Entry Archive File Path for <a href=
"http://ask-leo.com" target="_blank">Ask Leo!</a> is set to:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;$MTEntryTitle dirify="1"$&gt;.html</blockquote>
<p>This causes MT to use the Entry Title, "dirify" it (an MT function that
removes or replaces illegal characters and the like), and append a ".html". So,
for example, the pagename for my article entitled "How do I keep my computer
safe on the internet?" becomes:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/<br />
how_do_i_keep_my_computer_safe_on_the_internet.html</blockquote>
<p>Warning: there's a catch to this approach, though it's easily solved.</p>
<p>MT does not prevent two entries with the same title from overwriting one
another. So if I have two entries with the title "Test" both would get written
to "test.html". The most recent one written by MT would "win," and be
accessible, the other would disappear from the site (though not MT's
database).</p>
<p>In the case of <a href="http://ask-leo.com" target="_blank">Ask Leo!</a>
I've made the conscious decision to avoid duplicate titles. But that's not
always possible, or efficient. The solution? Append or prepend the entry ID to
the filename using this Individual Entry Archive File Path:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;$MTEntryTitle dirify="1"$&gt;_&lt;$MTEntryID pad="1"$&gt;.html</blockquote>
<p>This uses the title as before, but then appends an underscore, followed by
the six-digit entry ID and ".html". Since entry IDs are unique, entries with
identical titles will now have distinct filenames. If you have a look at the
individual entries at <a href="http://forwardedfunnies.com" target=
"_blank">ForwardedFunnies</a> you'll see I've taken this approach there.</p>]]>
    </content>
</entry>

<entry>
    <title>Changing Page Names Mid-Stream</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/changing_page_names_midstream.html" />
    <id>tag:www.MTTips.com,2006://5.1742</id>

    <published>2006-10-09T03:21:30Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>Ask Leo! was originally set up to name files using MovableType 2.x&apos;s default structure. Individual articles were archived with old style names of the form: http://ask-leo.com/archives/000001.html That works, but current thinking is that search engines &quot;like&quot; seeing keywords in URLs....</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tricks" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p><a href="http://ask-leo.com">Ask Leo!</a> was originally set up to name
files using MovableType 2.x's default structure. Individual articles were
archived with old style names of the form:
http://ask-leo.com/archives/000001.html</p>
<p>That works, but current thinking is that search engines "like" seeing
keywords in URLs. Since I wanted to do all I could to improve my search engine
rankings, I decided to change my page names from being numbered and in a
subdirectory to being the article title and in the root of the site.</p>
<p>Changing names midstream becomes a bit of a challenge. With several hundred
articles on the site already, I wanted to switch to the new naming scheme while
still allowing the old-style URLs, that people had perhaps bookmarked, to
work.</p>
<p>I'm presenting these steps in the order that you need to do them to a live,
running site. Review the entire set of steps before proceeding. If you follow
these steps in this order, your site should never appear "down" and links will
not be broken as you make this conversion.</p>]]>
        <![CDATA[<p><strong>Step 1 - Create a Mapping Index Template</strong></p>
<p>We'll start by creating some support infrastructure for the name change. The
first is the tool that will allow the old names to be redirected to the new
names.</p>
<p>The first step is creating a new template that actually writes a tiny
program in PHP. This program maps the internal article number to the new
"dirified" name.</p>
<p>In List Templates, create a new Index Template, called ArticleMap:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;?php<br />
&lt;MTEntries lastn='10000'&gt;<br />
  $rgEntries[&lt;$MTEntryID$&gt;] = "&lt;$MTEntryPermalink$&gt;";<br />
&lt;/MTEntries&gt;<br />
?&gt;</blockquote>
<p>Yes, that is the entire template. If your MT site has more than 10,000
articles, then feel free to increase the "lastn" number.</p>
<p>Configure its output file to be "articlemap.php".</p>
<p>This is an index template... meaning that it has access to all of the
entries, and is regenerated each time an article is added or modified.</p>
<p>Rebuild this template. You'll see that the created articlemap.php contains a
series of entries like this:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
$rgEntries[1] = "http://ask-leo.com/archives/000001.html";</blockquote>
<p>With the PHP indicators "&lt;?php" at the top and "?&gt;" at the bottom.</p>
<p><strong>Step 2 - Create the Redirector</strong></p>
<p>Create a new file "byid.php" in the root of your site, and place into it the
following:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;?php<br />
  include "articlemap.php";<br />
  $szLoc = "http://ask-leo.com";<br />
  $id = $_GET['id'] + 0;<br />
  if ("" != $rgEntries[$id])<br />
    $szLoc = $rgEntries[$id];<br />
  header ("location: $szLoc");<br />
?&gt;</blockquote>
<p>(You can also download this from <a href=
"http://mttips.com/files/byid.zip">http://mttips.com/files/byid.zip</a>).</p>
<p>This tiny PHP program uses the article map we created in Step 1. It takes as
a parameter an article number, looks up that article number in the mapping
table, and redirects to the corresponding page.</p>
<p>Replace the "ask-leo.com" in the script with the location you want visitors
to be redirected to should the look-up fail. As you can see I typically use the
home page, but you could redirect to an error page, or your website's 404
page.</p>
<p>Try it now. Try this link: http://ask-leo.com/byid.php?id=1, but:</p>
<ul>
<li>
<p>Use your own site instead of ask-leo.com.</p>
</li>
<li>
<p>Use an ID number that shows up in articlemap.php.</p>
</li>
</ul>
<p>You should be redirected to the permalink for the article number you
specified. (If you use the link as presented above, you'll go to the article
that was originally Ask Leo! article #1.)</p>
<p><strong>Step 3 - Rewrite the URLs</strong></p>
<p>Now that we have a script that will take an ID and redirect it to the
"right" page, we need to transform the incoming requests for what will become
the old style URLs using URL Rewriting.</p>
<p>Our goal is that an incoming request that looks like this:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/archives/000001.html</blockquote>
<p>should be processed as:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/byid.php?id=000001</blockquote>
<p>That's accomplished with the following URL Rewrite:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">RewriteRule
/([0-9]+)\.html$ /byid.php?id=$1 [PT]</blockquote>
<p>In English, that rule says that any incoming page request whose filename is
a series of numbers followed by ".html" be changed to a request for "byid.php"
with the "id" parameter set to equal the string of numbers. The string of
numbers, of course, is the MovableType ID for the article being requested.</p>
<p>So now, let's make sure that works. Did you notice that we didn't include
the word "archive" in the rewrite test? That's on purpose, because it means
that this should now also work:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/000001.html</blockquote>
<p>Remember to use your own site, and your own article ID for that test. Even
though there is no 000001.html in the root of your site, the rewrite to use
byid.php will trigger, and redirect you to the correct filename.</p>
<p><strong>Step 4 - Turn on 'dirified' Filenames</strong></p>
<p>OK, now it's time to change the filenames that MovableType saves your
articles as.</p>
<p>In your weblog config, under the Publishing tab, in the Archive Mapping
section (formerly the Archiving tab), set the Individual Entry Archive, Archive
File Path to:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;$MTEntryTitle dirify="1"$&gt;.html</blockquote>
<p style="text-align: center"><img src="/images/individualarchivename.png" alt=
"Individual Entry File Path" title="Individual Entry File Path" style=
"border: 1px solid black" /></p>
<p>MovableType uses this field as a kind of "mini template" for the filename to
be used for each entry. Be careful not to introduce any additional characters,
such as trailing spaces, because that will confuse both MovableType and
you.</p>
<p>Setting this field instructs MovableType to use the "dirified" entry title
(taking out or altering characters that would cause problems in filenames) plus
".html" as the filename to use for each article.</p>
<p>If it's possible, you may have more than one article with the same title,
then you can make sure that each article's filename is unique by including the
ID in the filename as well:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;$MTEntryTitle dirify="1"$&gt;_&lt;$MTEntryID$&gt;.html</blockquote>
<p>Since no two entries will have the same ID number, even if they have the
same title, this approach will guarantee that they have unique filenames.</p>
<p>NOW... the first scary test.</p>
<p>Rebuild your site. All of it.</p>
<p>Here is what will happen:</p>
<ul>
<li>
<p>MovableType will create new pages for all of your articles with the new
names as specified above.</p>
</li>
<li>
<p>Articlemap.php will be regenerated to use those filenames as the permalinks
to redirect to. This means that ...</p>
</li>
<li>
<p>byid.php will now start redirecting to the new names. This means that
...</p>
</li>
<li>
<p>Old requests using the old format:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/archives/000001.html</blockquote>
<p>will be redirected to their new names:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/archives/article_title.html</blockquote>
</li>
</ul>
<p>All other references throughout your MovableType weblog will also simply use
the new article file names.</p>
<p>Note that we're still using "archives" in the resulting URL. The last step
gets rid of that too.</p>
<p><strong>Step 5 - Move your archives to the root</strong></p>
<p>The default in MovableType 2.x was to place articles in a subdirectory off
of the root named "archives". I wanted my articles to be placed in the root of
my site instead (the theory being that files in the root might be perceived as
"more important" to the search engines).</p>
<p>In your weblog settings, under the Publishing tab (formerly the Core Setup
tab), remove "/archives" from the Archive Root (formerly the Local Archive
Path), and the Archive URL.</p>
<p>For example:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
/home/httpd/vhosts/ask-leo.com/html/archives</blockquote>
<p>Becomes</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
/home/httpd/vhosts/ask-leo.com/html</blockquote>
<p>And:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/archives/</blockquote>
<p>becomes simply</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/</blockquote>
<p>Together, those two settings instruct MovableType to place the files in the
desired location - the root of the site - and generate any references to them
in that location as well.</p>
<p>Time for the scary test again.</p>
<p>Rebuild your site. All of it.</p>
<p>Here's what will happen this time:</p>
<ul>
<li>
<p>MovableType will create new pages for all of your articles with the new
names as specified in the previous step, this time placing them in the root of
your site.</p>
</li>
<li>
<p>Articlemap.php will be regenerated to use those filenames in the root as the
permalinks to redirect to. This means that ...</p>
</li>
<li>
<p>byid.php will now start redirecting to the new names. This means that
...</p>
</li>
<li>
<p>Old requests using the old format:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/archives/000001.html</blockquote>
<p>will be redirected to their new names:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/article_title.html</blockquote>
<p>Exactly what we wanted.</p>
</li>
</ul>
<p>All other references throughout your MT weblog that MT generates will also
simply use the new article file names in their new location.</p>
<p>One you have this in place, you're done. You could stop at this point, if
you wished. You've successfully renamed and moved your articles, and no
visitors noticed while you were doing it.</p>
<p>But there is still a little clean up, and one more step that I have found
pretty handy:</p>
<p><strong>Step 6 - Rewrite the simplest URLs</strong></p>
<p>This step is entirely optional, and falls into the category of "while you're
in there anyway ..."</p>
<p>One side effect of using article titles in their URLs is that the URLs can
get kind of long. That's ok when the URL is being generated automatically and
referenced in web pages such as the rest of your MT website. But if you want to
perhaps send someone a pointer to a specific article, it can be rather
cumbersome.</p>
<p>We've seen already that the existing URL Rewrite allows us to still
reference an article as</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/0000001.html</blockquote>
<p>Well, it turns out that this also works:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/1.html</blockquote>
<p>Try it on your own site. Now, wouldn't it be handy to get rid of the
".html"? Wouldn't it be nice if you could simply point people at:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
http://ask-leo.com/1</blockquote>
<p>Because of everything we've done so far, we have all the pieces in place.
Just add one more URL Rewrite rule to make it happen:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">RewriteRule
/([0-9]+)$ /byid.php?id=$1 [PT]</blockquote>
<p>This redirects all URLs ending in "/" followed by a number to byid.php with
that number as the id parameter.</p>
<p><strong>Step 7 - Clean up your archives</strong></p>
<p>Even though we've moved our entries out of the archives directory, we've not
actually deleted any of the files therein. That's been kind of a safety
precaution so far. If, for example, the rewrite rules failed to operate, those
files would still be there for your visitors to access.</p>
<p>But now that you've moved everything and verified that it's all working
properly, you can remove the archives and free up the space associated with
them.</p>
<p>I recommend a two-stage approach:</p>
<ol>
<li>
<p>Rename the archives directory to something else like "delete-soon", for
example. Now, watch your site's error log for a while to make sure doing that
hasn't caused archive pages to not be found. It shouldn't add any errors
because if things are working properly, the references to all your archives
should be caught by URL Rewriting and redirected to their new, correct,
location. If renaming does cause pages to suddenly not be found, rename it back
to "archives" and review all the preceding steps, because something's not
working.</p>
</li>
<li>
<p>After you're convinced that renaming the archive directory hasn't introduced
any errors, delete it, and all its contents.</p>
</li>
</ol>
<p><strong>Now</strong> you're done.</p>]]>
    </content>
</entry>

<entry>
    <title>Get creative with Templates</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/get_creative_with_templates.html" />
    <id>tag:www.MTTips.com,2006://5.1741</id>

    <published>2006-07-23T22:47:25Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>There&apos;s nothing that says MovableType templates can&apos;t be added to create other types of files. The challenge I had was this: I want to be able to have a list of all my category archive pages on some of the...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>There's nothing that says MovableType templates can't be added to create
other types of files.</p>
<p>The challenge I had was this: I want to be able to have a list of all my
category archive pages on some of the other pages that are not built by
MovableType.</p>
<p>The solution? Create an index template that contains that list - and only
that list - and have it produce an include file that I can use anywhere I
like.</p>]]>
        <![CDATA[<p>Here is the template, in its entirety:</p>
<blockquote>&lt;p&gt;&lt;b&gt;&lt;a href="/archives.html"&gt;The Full
Archive&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;<br />
&lt;MTSubCategories&gt;<br />
 &lt;MTSubCatIsFirst&gt;&lt;/MTSubCatIsFirst&gt;<br />
 &lt;p style="font-weight: normal; margin-top: 0; margin-bottom:
0;"&gt;&amp;bull; &lt;a
href="&lt;$MTCategoryArchiveLink$&gt;"&gt;&lt;$MTCategoryLabel$&gt;&lt;/a&gt;&lt;/p&gt;<br />

 &lt;MTSubCatIsLast&gt;&lt;/MTSubCatIsLast&gt;<br />
&lt;/MTSubCategories&gt;</blockquote>
<p>We'll create that as a new index template, called "catlist.inc":</p>
<p style="text-align:center;"><img src="/images/catlistindex.png" alt=
"Index Listing with Catlist" style="border: 1px solid black" /></p>
<p>Now, when we cause a rebuild of the indexes, catlist.inc is updated. Here's
what the beginning of that file looks like as I write this:</p>
<blockquote style="border: 1px solid black">&lt;p&gt;&lt;b&gt;&lt;a
href="/archives.html"&gt;The Full Archive&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;<br />
&lt;p style="font-weight: normal; margin-top: 0; margin-bottom:
0;"&gt;&amp;bull; &lt;a
href="http://ask-leo.com/administration.html"&gt;Administration&lt;/a&gt;&lt;/p&gt;<br />

&lt;p style="font-weight: normal; margin-top: 0; margin-bottom:
0;"&gt;&amp;bull; &lt;a
href="http://ask-leo.com/email.html"&gt;EMail&lt;/a&gt;&lt;/p&gt;<br />
&lt;p style="font-weight: normal; margin-top: 0; margin-bottom:
0;"&gt;&amp;bull; &lt;a
href="http://ask-leo.com/general_computing.html"&gt;General
Computing&lt;/a&gt;&lt;/p&gt;<br />
...</blockquote>
<p>That's a fine file that can be included elsewhere. For example, on my actual
"Ask a Question" page, <a href="http://ask-leo.com/askleo.html" target=
"_blank">http://ask-leo.com/askleo.html</a>, which is a manually created page,
below the entry form for a question you'll see a list of the categories
available for browsing:</p>
<p style="text-align:center;"><img src="/images/archivelist.png" alt=
"Archive List in Ask Leo! page" style="border: 1px solid black" /></p>
<p>That's the result of the following include:</p>
<blockquote>&lt;!--#include VIRTUAL="catlist.inc" --&gt;</blockquote>
<p>If that looks very similar to the category list that's presented on the Ask
Leo! homepage, it should ... the home page uses the exact same include to
present the category list.</p>]]>
    </content>
</entry>

<entry>
    <title>Get creative with HTML</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/get_creative_with_html.html" />
    <id>tag:www.MTTips.com,2006://5.1740</id>

    <published>2006-06-24T22:46:31Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary> Remember that the goal of the templates is simply to transform your content into your desired results - normally HTML pages for display. When dealing with templates, it&apos;s easy to think that you have to do everything using MT&apos;s...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[  <p>
   Remember that the goal of the templates is simply to transform your content into your desired results - normally HTML pages for
   display.
  </p>
  <p>
   When dealing with templates, it's easy to think that you have to do everything using MT's constructs and easier still to get
   stuck into the rut of using only the examples or variations of the default templates.
  </p>]]>
        <![CDATA[<p>
   Take the category list, for example. The most common category list is generated as follows:
  </p>
   <blockquote>
   &lt;MTArchiveList archive_type="Category"&gt;<br />
   &nbsp;&nbsp;&lt;a href="&lt;$MTArchiveLink$&gt;"&gt;&lt;$MTArchiveTitle$&gt;&lt;/a&gt;&lt;br/&gt;<br />
   &lt;/MTArchiveList&gt;
  </blockquote>
  <p>
   Which generates a list of all your categories, that are clickable to get to their corresponding archives. On Ask Leo! the result
   would begin like this:
  </p>
  <blockquote>
   Administration<br />
   EMail<br />
   General Computing<br />
   Hardware<br />
   Instant Messaging
  </blockquote>
  <p>
   and so on...
  </p>
  <p>
   Since I have a lot of categories, it can take up a fair amount of the page's real-estate. For a time I decided to use a
   drop-down list. Quite easily done with the following template fragment:
  </p>
  <blockquote>
   &lt;select onchange="window.location.href = this.value;"&gt;<br />
   &nbsp;&nbsp;&lt;option value="/" SELECTED&gt;Select...&lt;/option&gt;<br />
   &nbsp;&nbsp;&lt;option value="/archives.html"&gt;The Full Archive&lt;/option&gt;<br />
   &nbsp;&nbsp;&lt;MTArchiveList archive_type="Category"&gt;<br />
   &nbsp;&nbsp;&nbsp;&nbsp;&lt;option value="&lt;$MTArchiveLink$&gt;"&gt;&lt;$MTArchiveTitle$&gt;&lt;/option&gt;<br />
   &nbsp;&nbsp;&lt;/MTArchiveList&gt;<br />
   &lt;/select&gt;&lt;br/&gt;
  </blockquote>
  <p>
   Here's the old "Administration" category archive page:
  </p>
  <p style="text-align:center;">
   <img src="/images/dropdown.png" alt="MT Generated Dropdown" style="border: 1px solid black" />
  </p>
  <p>
   Note the dropdown list on the right. Here it is again, with the list opened:
  </p>
  <p style="text-align:center;">
   <img src="/images/dropdownopen.png" alt="MT Generated Dropdown Open" style="border: 1px solid black" />
  </p>
  <p>
   If you go back and look at the template fragment, you can see that the items "Select..." and "The Full Archive" are manual, hard
   coded entries in the list, but the rest of the dropdown is created when MT processes the template and builds the HTML output.
  </p>
  <p>
   This is just an example. The true "tip" here is to use your knowledge and familiarity with HTML to look outside of the default
   templates.
  </p>]]>
    </content>
</entry>

<entry>
    <title>Repurpose the Excerpt</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/repurpose_the_excerpt.html" />
    <id>tag:www.MTTips.com,2006://5.1739</id>

    <published>2006-06-13T17:45:00Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>I found myself wanting to add a &quot;Summary&quot; for each article on Ask Leo! The summary is written by hand for each article - partly for the search engines, and partly to help people decide whether the article is, in...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>I found myself wanting to add a "Summary" for each article on <a href=
"http://ask-leo.com">Ask Leo!</a> The summary is written by hand for each
article - partly for the search engines, and partly to help people decide
whether the article is, in fact, what they're looking for.</p>
<p>One complicating factor is that with over 860 articles, I wasn't about to
add summaries for most. So I wanted summaries to be visible only if a summary
had, indeed been written.</p>
<p>As we all know, there is no "Summary" field in MovableType, instead there's
something called an "Excerpt". Excerpt serves my purposes well, but only after
a minor configuration change.</p>]]>
        <![CDATA[<p>In my Individual Entry Archive template, I now include the following:</p>
<blockquote style="font-family: 'Courier New', Courier, monospace;">
&lt;MTIfNonEmpty tag="EntryExcerpt"&gt;<br />
  &lt;p style="..."&gt;&lt;b&gt;Summary&lt;/b&gt;:
&lt;$MTEntryExcerpt$&gt;&lt;/p&gt;<br />
&lt;/MTIfNonEmpty&gt;</blockquote>
<p>That seems fairly straightforward, right? There's only one problem. The
Excerpt is, by default, automatically generated from the first 'n' words of
your content if not explicitly supplied. As a result, the tag was always
non-empty, and every article had a "Summary", whether or not I had written
one.</p>
<p>The solution turned out to be fairly simple.</p>
<p>In the <strong>Settings</strong> for the weblog, I set <strong>Excerpt
Length</strong> to zero.</p>
<p>Now, the default Excerpt is, indeed, empty. If I purposely fill in the
Excerpt, then it exists, and the condition in my template triggers, and the
Excerpt ... no, Summary ... appears.</p>
<p>I know that there are other plug-ins for MT that allow you to add additional
fields to each entry, but I thought this was a rather convenient use of
built-in functionality to effectively re-purpose the Excerpt field.</p>
<p>But, of course, you can only do that once. As soon as I need something in
addition to my Summary, I'll be looking at other options.</p>]]>
    </content>
</entry>

<entry>
    <title>Dealing with a Wealth of Comments</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/dealing_with_a_wealth_of_comments.html" />
    <id>tag:www.MTTips.com,2006://5.1738</id>

    <published>2006-04-28T22:44:15Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary><![CDATA[ One of the interesting things about writing a technical Q&amp;A site that deals primarily with Microsoft Windows is that people have no shortage of questions - and opinions. Lots of questions and lots of opinions. When some article pages...]]></summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[  <p>
   One of the interesting things about writing a technical Q&amp;A site that deals primarily with Microsoft Windows is that people
   have no shortage of questions - and opinions. Lots of questions and lots of opinions. When some article pages became slow to
   load due to there being literally hundreds of comments I needed a solution. What I found was a MovableType extension:
   <a href="d-mtpaginate" target="_blank">MTPaginate</a>.
  </p>
  <p>
   Have a look at the article <a href="http://ask-leo.com/what_are_lsass_lsassexe_and_sasser_and_how_do_i_know_if_im_infected_what_do_i_do_if_i_am.html" target="_blank">What are "LSASS", "LSASS.EXE" and "Sasser" and how do I know if I'm infected? What do I do if I am?</a> -
   it's one of my most viewed articles. One of the most commented on also. As I type this there are almost 400 comments on the
   article. Displaying all 400 at once (the way that MovableType's default templates work) would make for a very unwieldy page.
  </p>
  <p>
   Now my approach is this:
  </p>]]>
        <![CDATA[  <p>
   First, the individual entry template only shows the 10 most recent comments:
  </p>
  <blockquote>
   &lt;MTComments lastn="10"&gt;
  </blockquote>
  <p>
   If you visit the 
   <a href="http://ask-leo.com/what_are_lsass_lsassexe_and_sasser_and_how_do_i_know_if_im_infected_what_do_i_do_if_i_am.html" target="_blank">LSASS article</a>
   referenced above, you'll see the results.
  </p>
  <p>
   Second, I've created an additional entry template for paged comments:
  </p>
  <p style="text-align:center">
   <img src="/images/pagedtemplate.png" alt="Page Entry Template in MT"  style="border: thin solid black" />
  </p>
  <p>
   That template is much like the individual entry archive, except:
  </p>
  <ul>
   <li>It does not contain the article
   </li>
   <li>It only lists comments
   </li>
   <li>It uses MTPaginate to break the comments into pages of 10 each
   </li>
   <li>It does not include a comment form, but rather a link back to the original article page where comments can be entered.
   </li>
  </ul>
  <p>
   MTPaginate also requires that the pages be processed by PHP, a server-side programming language, so as a result the output of
   the Page Comments template is a .php file.
  </p>
  <p>Here's the "meat" of the paged comments template:</p>
  <blockquote><pre>
      &lt;MTPaginate&gt;
       &lt;h2&gt;Comments&lt;/h2&gt;
       &lt;div class="comments-head"&gt;&lt;a name="comments"&gt;&lt;/a&gt;
        All Comments on: &lt;a href="&lt;$MTEntryLink$&gt;"&gt;&lt;$MTEntryTitle$&gt;&lt;/a&gt;
       &lt;/div&gt;
       &lt;div class="comments-body"&gt;
        &lt;p&gt;
         (&lt;a href="&lt;$MTEntryLink$&gt;"&gt;Read the article&lt;/a&gt;
         that everyone's commenting on.
        &lt;/p&gt;
       &lt;/div&gt;
       &lt;MTPaginateIfMultiplePages&gt;
        &lt;div class="comments-body"&gt;Comment Page: &lt;$MTPaginateNavigator$&gt;&lt;/div&gt;
       &lt;/MTPaginateIfMultiplePages&gt;
       &lt;MTEntryIfNoComments&gt;
        &lt;div class="comments-body"&gt;
         &lt;p&gt;There are no comments on this article yet.&lt;/p&gt;
        &lt;/div&gt;
       &lt;/MTEntryIfNoComments&gt;
       &lt;MTPaginateContent max_sections="10"&gt;
        &lt;MTComments&gt;
         &lt;div class="comments-body"&gt;
           &lt;$MTCommentBody$&gt;
           &lt;span class="comments-post"&gt;
            Posted by: &lt;b&gt;&lt;MTCommentAuthor default="Anonymous"&gt;&lt;/b&gt;
            at &lt;$MTCommentDate$&gt;
           &lt;/span&gt;
         &lt;/div&gt;
        &lt;MTPaginateSectionBreak&gt;
        &lt;/MTComments&gt;
       &lt;/MTPaginateContent&gt;
       &lt;MTPaginateIfMultiplePages&gt;
        &lt;div class="comments-body"&gt;Comment Page: &lt;$MTPaginateNavigator$&gt;&lt;/div&gt;
       &lt;/MTPaginateIfMultiplePages&gt;
       &lt;div class="comments-body"&gt;
        &lt;p&gt;(&lt;a href="&lt;$MTEntryLink$&gt;"&gt;Read the article&lt;/a&gt; that everyone's commenting on.)&lt;/p&gt;
       &lt;/div&gt;
       &lt;MTEntryIfCommentsOpen&gt;
         &lt;div class="comments-head"&gt;Post a Comment&lt;/div&gt;
         &lt;div class="comments-body"&gt;
         &lt;p&gt;To post a comment on &lt;a href="&lt;$MTEntryLink$&gt;"&gt;"&lt;$MTEntryTitle$&gt;"&lt;/a&gt;, please return
         to that &lt;a href="&lt;$MTEntryLink$&gt;"&gt;article's main page&lt;/a&gt;.&lt;/p&gt;
         &lt;/div&gt;
       &lt;/MTEntryIfCommentsOpen&gt;
      &lt;/MTPaginate&gt;
  </pre>
  </blockquote>
  <p>MTPaginate still generates a single output file, but by using PHP, that file takes parameters that  then
  control which comments are actually displayed.</p>
  <p>
   If you click on the "<a href="http://ask-leo.com/comments_000194.php?page=1" target="_blank">See all 390 comments...</a>" link (or whatever the number is today), you'll be taken to the results. At the top
   and bottom of that page will be a traditional navigation list of page numbers:
  </p>
  <p style="text-align:center">
   <img src="/images/pagedpagebar.png" alt="Paging Navigation on Multiple comment pages"  style="border: thin solid black" />
  </p>
  <p>
   10 comments are displayed on each page. If you look at the URL behind each of the links, you'll see that they
   refer to the same page, only with an additional parameter:
  </p>
  <blockquote>
  http://ask-leo.com/comments_000194.php?page=2
  </blockquote>
  <p>Where the "page=" parameter defines which group of comments to display.
  <p>
   <a href="d-mtpaginate" target="_blank">MTPaginate</a> is a valuable solution for articles that generate lots of comments. I encourage you to check it out.
  </p>]]>
    </content>
</entry>

<entry>
    <title>MovableType Styles</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/movabletype_styles.html" />
    <id>tag:www.MTTips.com,2006://5.1737</id>

    <published>2006-04-24T05:26:17Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>The default set of templates that come with MovableType make extensive use of the stylesheet &quot;styles-site.css&quot;. It&apos;s possible, by manipulating only the stylesheet, to achieve dramatically different looks for a site based on the default templates. MT&apos;s default CSS is...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>The default set of templates that come with MovableType make extensive use
of the stylesheet "styles-site.css". It's possible, by manipulating only the
stylesheet, to achieve <em>dramatically</em> different looks for a site based
on the default templates.</p>
<p>MT's default CSS is <em>far</em> from trivial, nor is it documented anywhere
that I can find. It requires an investment of time to understand. My original
"Tip" was to invest that time understanding the default CSS.</p>]]>
        <![CDATA[<p>With the 3.2 release of MT, the default styles increased in complexity by an
order of magnitude. If you're alreay CSS conversant, and have the time,
understanding exactly how these styles work may be worth your time. However I
can no longer recommend it for the average user.</p>
<p>So, I now have two tips:</p>
<p><strong>Keep using the default styles</strong>, but make only minimal
changes. One approach might be <a href=
"http://www.sixapart.com/movabletype/styles/">StyleCatcher</a>, an MT plugin
that allows you to select a style from a collection of styles in real time. As
long as you use the default templates and styles, you can change the look and
feel of your blog completely - with a mouse click or two. My site <a href=
"http://www.tamingemail.com">Taming Email</a> uses a StyleCatcher style.</p>
<p><strong>Start from scratch.</strong> This'll require a little more
understanding not of the styles, but of the MT templating syntax. The basics
are relatively simple, but the total templating language is very powerful and
flexible. The style sheet and templates for this site, for example, are
extremely simple, very clean, and much less confusing than the default MT
templates.</p>]]>
    </content>
</entry>

<entry>
    <title>Reader Comments</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/reader_comments.html" />
    <id>tag:www.MTTips.com,2006://5.1736</id>

    <published>2006-04-24T05:17:35Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>Rather than sprinkle comments throughout MovableType Tips, I&apos;m setting aside this item specifically for your questions and feedback....</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="General" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>Rather than sprinkle comments throughout <b>MovableType Tips</b>, I'm setting aside this item specifically for your questions and feedback.</p>]]>
        <![CDATA[<p>&bull;</p><br />]]>
    </content>
</entry>

<entry>
    <title>Get between your Entry Body and Extended Entry</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/get_between_your_entry_body_and_extended_entry.html" />
    <id>tag:www.MTTips.com,2006://5.1735</id>

    <published>2006-04-23T04:32:53Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>When you create a new entry in MT, you&apos;re presented with the default entry form that contains areas for both an Entry Body and an Extended Entry. Most folks use them for either of two purposes: The entry body is...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>When you create a new entry in MT, you're presented with the default entry
form that contains areas for both an Entry Body and an Extended Entry. Most
folks use them for either of two purposes:</p>
<ol>
<li>The entry body is the "tease" portion of the entry that goes on to the home
page, while the extended entry is the rest of the entry that shows up only on
the entry's individual archive page.</li>
<li>The entry body is what shows up in the RSS feed. The extended entry is the
rest of the entry that shows up only on the entry's individual archive
page.</li>
</ol>]]>
        <![CDATA[<p>As you can probably guess, those are really two instances of the same
principal. And it's a principal I use on Ask Leo! quite successfully, for both
RSS and the Ask Leo! home page.</p>
<p>The nice thing about having the article broken into two pieces like that is
that you can insert something between the two pieces in your template. For
example, the Ask Leo! individual entry archive contains this fragment:</p>
<blockquote>
<pre>
&lt;$MTEntryBody$&gt;
&lt;a name="more"&gt;&lt;/a&gt;
&lt;div id="entrygoogle"&gt;
  &lt;!--#include VIRTUAL="googleads336x280.inc" --&gt;
&lt;/div&gt;
&lt;p style="text-align:center"&gt;&bull;&lt;/p&gt;
&lt;$MTEntryMore$&gt;
</pre></blockquote>
<p>In-between the &lt;$MTEntryBody$&gt; and the &lt;$MTEntryMore$&gt; tags,
I've placed a &lt;div&gt; in which there's an include statement. As you might
guess from the name, that include file contains my Google Adsense code which
causes the ads to be displayed in the body of the entry, rather than before or
after it. In fact the CSS style for ID "entrygoogle" allows me to further
control positioning relative to this insertion point:</p>
<blockquote>
<pre>
#entrygoogle
{
  background-color: #FFFFFF;
  float:right;
  padding-left:15px;
}
</pre></blockquote>
<p>The "float" option allows the text of the article to wrap around the ad
block.</p>]]>
    </content>
</entry>

<entry>
    <title>Next and Previous - Within a Category</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/next_and_previous_within_a_category.html" />
    <id>tag:www.MTTips.com,2006://5.1734</id>

    <published>2006-02-18T23:35:48Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary><![CDATA[MT automatically gives you the next and previous items for your individual archives with &lt;MTEntryNext&gt; and &lt;MTEntryPrevious&gt; items. The problem is that's within the global list of all entries within your blog. What if you wanted to link to the...]]></summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>MT automatically gives you the next and previous items for your individual
archives with <code>&lt;MTEntryNext&gt;</code> and
<code>&lt;MTEntryPrevious&gt;</code> items. The problem is that's within the
global list of all entries within your blog. What if you wanted to link to the
next or previous item within a given category?</p>
<p>As an example, check out any of the entries on <a href=
"http://www.forwardedfunnies.com" target="_blank">Forwarded Funnies</a>. There,
in the upper right, you'll see not only a previous and next for "All Entries",
but a separate previous and next for entries of the same rating as the current.
In other words a previous and next for all the "G-Rated" entries if the current
item is itself G-rated.</p>
<p>Needless to say, ratings within Forwarded Funnies are simply separate MT
categories.</p>
<p>My approach uses a combination of PHP code generated from a category archive
template, and a <a href="/use_serverside_includes.html">server-side
include</a>, or "SSI", in the individual entry archive template.</p>]]>
        <![CDATA[<p>The category archive template I added is this:</p>
<blockquote>
<pre>
&lt;?
    $szID = $_GET['id'];
    $szOp = $_GET['op'];
    $szText = $_GET['text'];

    &lt;MTEntries sort_order="ascend"&gt;
     $rgArchive[&lt;$MTEntryID$&gt;] = "&lt;$MTEntryPermalink$&gt;";
     $rgTitle[&lt;$MTEntryID$&gt;] = &lt;&lt;&lt;H&lt;$MTEntryID$&gt;
&lt;$MTEntryTitle$&gt;
H&lt;$MTEntryID$&gt;;
    &lt;/MTEntries&gt;

    if (array_key_exists ($szID, $rgArchive))
      {
      while (key ($rgArchive) != $szID)
        {
        $szPrev = key ($rgArchive);
        next ($rgArchive);
        }
      $szNext = next ($rgArchive);
      $szNext = key ($rgArchive);
      
      if (("next" == $szOp) &amp;&amp; ("" != $szNext))
        echo "$szText &lt;a href=\"" . $rgArchive[$szNext] 
            . "\"&gt;" . $rgTitle[$szNext] . "&lt;/a&gt;";
      elseif (("prev" == $szOp) &amp;&amp; ("" != $szPrev))
        echo "$szText &lt;a href=\"" . $rgArchive[$szPrev]
            . "\"&gt;" . $rgTitle[$szPrev] . "&lt;/a&gt;";
      }
?&gt;
</pre></blockquote>
<p>The MT Entries section generates PHP code such as this:</p>
<blockquote>
<pre>
  $rgArchive[500] = "http://www.forwardedfunnies.com/do_not_be_late_000500.html";
  $rgTitle[500] = &lt;&lt;&lt;H500
Do Not Be Late
H500;
  $rgArchive[501] = "http://www.forwardedfunnies.com/jesus_mary_joseph_and__000501.html";
  $rgTitle[501] = &lt;&lt;&lt;H501
Jesus, Mary, Joseph and ...
H501;
</pre></blockquote>
<p>In other words, it defines two arrays that map the item's <em>ID</em> to its
<em>Title</em> and <em>Permalink</em>. When used, this PHP code takes an entry
ID as a parameter, and then outputs a link to either the next or previous item
in the list.</p>
<p>We'll see exactly how that's used in just a second. First, I have to make
sure that the files generated when this template is built are named
appropriately.</p>
<p>In the weblog's <strong>Settings</strong>, in the
<strong>Publishing</strong> tab, down in <strong>Archive Mapping</strong>, I
created a new Archive Mapping for our new template. It is, as we said, a
Category archive, using the new template we added above.</p>
<p>Most importantly, I defined the <strong>Archive File Path</strong> to be:
"catnav_%c.php"</p>
<p style="text-align:center"><img src="/images/catnav_archive_mapping.png" alt=
"Archive Mapping for Category Navigator" /></p>
<p>This will then cause a category navigator, as I call it, to be built for
each category defined in the system. For example:</p>
<blockquote>catnav_grated.php<br />catnav_pgrated.php<br />...</blockquote>
<p>Now, to hook it up with the individual entries.</p>
<p>In the individual entry template, I place this code:</p>
<blockquote>
<pre>
&lt;MTEntryCategories&gt;
  &lt;br /&gt;
  &lt;a href="&lt;$MTCategoryArchiveLink$&gt;"&gt;&lt;b&gt;&lt;$MTCategoryLabel$&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; Entries:&lt;/b&gt;&lt;br /&gt;
  &lt;!--#include VIRTUAL="catnav_&lt;$MTCategoryLabel dirify="1" $&gt;.php?id=&lt;$MTEntryID$&gt;&amp;op=next&amp;text=Next:" --&gt;&lt;br /&gt;
  &lt;!--#include VIRTUAL="catnav_&lt;$MTCategoryLabel dirify="1" $&gt;.php?id=&lt;$MTEntryID$&gt;&amp;op=prev&amp;text=Previous:" --&gt;&lt;br /&gt;
&lt;/MTEntryCategories&gt;
</pre></blockquote>
<p>There are several interesting parts to this fragment, so I'll go over them
one by one.</p>
<p>First, note the use of "&lt;MTEntryCategories&gt;". While within Forwarded
Funnies, each item is assigned only one category, that's not a required
limitation. So the code that we'll generate here will be repeated once for each
category that this entry is assigned.</p>
<p>I start with a link to "&lt;$MTCategoryArchiveLink$&gt;" - that's a link to
the standard category archive page that simply lists all entries that have been
assigned the category. Nothing really new here.</p>
<p>I invoke the appropiate "catnav_??.php" within an SSI. This requires a
little more detailed explanation:</p>
<ul>
<li>
<p>"<em>catnav_&lt;$MTCategoryLabel dirify="1" $&gt;.php</em>" gives me the
name of the category navigator for the current category, dirified so that
improper characters are removed. A G-Rated item will result in
<em>"catnav_grated.php"</em> being the file processed by the SSI command.</p>
</li>
<li>
<p>The ".php" file is passed parameters as part of its execution by the
SSI.</p>
</li>
<li>
<p>"id=&lt;$MTEntryID$&gt;" passes the ID of the current entry to the .php
script.</p>
</li>
<li>
<p>"op=next" or "op=prev" tells the script whether to get the next or the
previous entry relative to the current entry.</p>
</li>
<li>
<p>"text=Next:" or "text=Previous:" is additional text that the script should
include, but only if it does, in fact, output an entry. There is no next for
the last item, and no previous for the first, in which case this text is not
output.</p>
</li>
</ul>
<p>Note that I include the SSI twice - once with parameters indicating that the
next item be fetched, and once again for the previous.</p>
<p>When all is said and done, each entry has a next and previous link within
their category, something like this:</p>
<blockquote>
<pre>
<a href=
"http://www.forwardedfunnies.com/grated.html"><strong>G-Rated</strong></a><strong> Entries:</strong>
Next: <a href=
"http://www.forwardedfunnies.com/horse_for_sale_009802.html">Horse For Sale</a>
Previous: <a href=
"http://www.forwardedfunnies.com/colorado_barbie_009819.html">Colorado Barbie</a>
</pre></blockquote>
<p>Or, in HTML:</p>
<blockquote>
<pre>
&lt;a href="http://www.forwardedfunnies.com/grated.html"&gt;&lt;b&gt;G-Rated&lt;/b&gt;&lt;/a&gt;&lt;b&gt; Entries:&lt;/b&gt;&lt;br /&gt;
Next: &lt;a href="http://www.forwardedfunnies.com/horse_for_sale_009802.html"&gt;Horse For Sale&lt;/a&gt;&lt;br /&gt;
Previous: &lt;a href="http://www.forwardedfunnies.com/colorado_barbie_009819.html"&gt;Colorado Barbie&lt;/a&gt;&lt;br /&gt;
</pre></blockquote>]]>
    </content>
</entry>

<entry>
    <title>Dealing with Comment Spam</title>
    <link rel="alternate" type="text/html" href="http://MTTips.com/dealing_with_comment_spam.html" />
    <id>tag:www.MTTips.com,2006://5.1733</id>

    <published>2006-02-15T01:33:00Z</published>
    <updated>2008-10-08T20:50:58Z</updated>

    <summary>Comment spam is the bane of the modern weblog. In an effort to boost their own ranking in the search engines, nefarious webmasters create software tools or &quot;bots&quot; that go out, find weblogs, and post scores of comments which contain...</summary>
    <author>
        <name>Leo</name>
        
    </author>
    
        <category term="Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://MTTips.com/">
        <![CDATA[<p>Comment spam is the bane of the modern weblog. In an effort to boost their
own ranking in the search engines, nefarious webmasters create software tools
or "bots" that go out, find weblogs, and post scores of comments which contain
links back to their sites. Those links are then seen by the search engines,
which use the general rule that "the more people link to you, the more
important you must be". The goal of comment spam is that the spammers' websites
about poker, Viagra and body part enlargement get better search engine ranking
as a result.</p>
<p>As weblog owners, not only do we not want to help the spammers, but we also
just don't want their off-topic posts included in our weblogs.</p>]]>
        <![CDATA[<p>I've tried several techniques to combat comment spam. The most effective I
found prior to switching to MT 3.1 was something called a "captcha" test
(completely automated public Turing test to tell computers and humans apart) -
you've seen them, they're the tests where before you can do something you need
to type in the letters presented in a distorted image. Computers can't read the
image (yet), but humans can. I used the captcha plugin developed by James Seng
with great success.</p>
<p>MT 3.1 did some major rework on comment entry and user validation in order
to enable TypeKey. Now, TypeKey is fine, but to me it seems yet another place
people would have to log in, and yet another barrier to legitimate comments.
Unfortunately that rework seems to have broken the Captcha test, and I was
unable to get it to work.</p>
<p>So, after all that backstory, here's my current approach on Ask Leo!:</p>
<ul>
<li>
<p>I have only one comment entry form for each article: on its main page.</p>
</li>
<li>
<p>I've replaced all other comment entry forms with a pointer to that comment
entry form on the main page of each entry. Thus there is only one place to
enter a comment on any particular entry.</p>
</li>
<li>
<p>I've modified the &lt;FORM&gt; tag for the comment form in the entry
template to begin with this:</p>
<blockquote>
<pre>
&lt;form method="post" action="commentspam.html"
    name="comments_form" ...
</pre></blockquote>
<p>Note that the action of the form has been changed to a static html page.</p>
</li>
<li>I created a static page, "commentspam.html" with the following text:
<blockquote>If you're seeing this page, either you have javascript turned off
in your browser (it's required in order to post a comment), or it looks like
you're using one of the techniques comment-spammers use.</blockquote>
</li>
<li>
<p>I added these two lines after the existing &lt;script&gt; just beneath the
comment &lt;form&gt; in the entry template:</p>
<blockquote>
<pre>
&lt;script type="text/javascript" language="javascript"
    src="comment.js"&gt;
&lt;/script&gt;
</pre></blockquote>
</li>
<li>I renamed MT's comment submission script to "something.pl", and updated the
"CommentScript" setting in my mt.cfg.</li>
<li>
<p>And lastly, I created "comment.js", placed it in the root of my website. It
contains only this:</p>
<blockquote>document.comments_form.action =
"http://pugetsoundsoftware.com/cgi-bin/something.pl"</blockquote>
</li>
</ul>
<p>The goal of all that is to rename the comment submission script, and make it
difficult for the spam-bots to determine what it is. Most spam-bots either
assume the name of the comment script and just post directly to it, or they
scan a weblog entry for the &lt;FORM&gt; and read the name of the script from
the "action=" attribute.</p>
<p>In my case, the default comment script name doesn't exist. The "action="
attribute points to a completely different page ... one that, if invoked, is
nothing more than a static html page. (Have a look:
http://ask-leo.com/commentspam.html).</p>
<p>The magic behind this trick is the javascript in comment.js. When the
&lt;script&gt; line that references it is loaded by a browser, the script
executes, and changes the "action=" for the form from the static html page to
the "real" comment script, which I've currently named something.pl.</p>
<p>In order for a spambot to successfully start comment-spamming me again, they
would need to do either of two things: begin parsing javascript, or actually
step through using the form on the entry page, rather than attempting to go
directly to the comment submission script.</p>
<p>Now, it's important to notice that this technique is not fool proof - quite
literally, actually: any fool can manually enter a spam-ish or abusive comment
by hand, and there are definitely fools out there. The tools the spammers are
using eventually overcome the roadblocks that we put in front of them,
especially as specific techniques become more common. I fully expect that this
technique will get broken, and I'll end up obfuscating my comment posting
approach in some other way.</p>
<p>But for now, zero automated comment spams have been posted in the several
months this technique has been in use.</p>]]>
    </content>
</entry>

</feed>
