Leo's MovableType Tips

by Leo A. Notenboom

by Ask Leo!

Dealing with a Wealth of Comments

One of the interesting things about writing a technical Q&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: MTPaginate.

Have a look at the article What are "LSASS", "LSASS.EXE" and "Sasser" and how do I know if I'm infected? What do I do if I am? - 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.

Now my approach is this:

First, the individual entry template only shows the 10 most recent comments:

<MTComments lastn="10">

If you visit the LSASS article referenced above, you'll see the results.

Second, I've created an additional entry template for paged comments:

Page Entry Template in MT

That template is much like the individual entry archive, except:

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.

Here's the "meat" of the paged comments template:

      <MTPaginate>
       <h2>Comments</h2>
       <div class="comments-head"><a name="comments"></a>
        All Comments on: <a href="<$MTEntryLink$>"><$MTEntryTitle$></a>
       </div>
       <div class="comments-body">
        <p>
         (<a href="<$MTEntryLink$>">Read the article</a>
         that everyone's commenting on.
        </p>
       </div>
       <MTPaginateIfMultiplePages>
        <div class="comments-body">Comment Page: <$MTPaginateNavigator$></div>
       </MTPaginateIfMultiplePages>
       <MTEntryIfNoComments>
        <div class="comments-body">
         <p>There are no comments on this article yet.</p>
        </div>
       </MTEntryIfNoComments>
       <MTPaginateContent max_sections="10">
        <MTComments>
         <div class="comments-body">
           <$MTCommentBody$>
           <span class="comments-post">
            Posted by: <b><MTCommentAuthor default="Anonymous"></b>
            at <$MTCommentDate$>
           </span>
         </div>
        <MTPaginateSectionBreak>
        </MTComments>
       </MTPaginateContent>
       <MTPaginateIfMultiplePages>
        <div class="comments-body">Comment Page: <$MTPaginateNavigator$></div>
       </MTPaginateIfMultiplePages>
       <div class="comments-body">
        <p>(<a href="<$MTEntryLink$>">Read the article</a> that everyone's commenting on.)</p>
       </div>
       <MTEntryIfCommentsOpen>
         <div class="comments-head">Post a Comment</div>
         <div class="comments-body">
         <p>To post a comment on <a href="<$MTEntryLink$>">"<$MTEntryTitle$>"</a>, please return
         to that <a href="<$MTEntryLink$>">article's main page</a>.</p>
         </div>
       </MTEntryIfCommentsOpen>
      </MTPaginate>
  

MTPaginate still generates a single output file, but by using PHP, that file takes parameters that then control which comments are actually displayed.

If you click on the "See all 390 comments..." 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:

Paging Navigation on Multiple comment pages

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:

http://ask-leo.com/comments_000194.php?page=2

Where the "page=" parameter defines which group of comments to display.

MTPaginate is a valuable solution for articles that generate lots of comments. I encourage you to check it out.