1 Maii 2003

Comments in archive templates

This is entirely out of sequence, but Loren asked, so I might as well share.

An issue noted by many Movable Type users is the server overhead of putting together the comments screen anew every time someone clicks on a Comments link. One way to lessen the burden is to include comments (rather than a comments link) directly into your archive pages. If you use Individual archive pages (as Loren does), it’s even possible to include the commenting form as well.

First, you need to figure out where to put the code in the template. Look for the end-tag for the placeholder </MTEntries>. If your template is like most, there is a div end-tag right above it that is probably the end of each blog entry. Just above that is where you want your comments and trackbacks.

Here’s a copy of the comment-and-trackback inclusion template that I use for the archive pages on Ravings. It’s a little rough-and-ready (all those grotty evil <br /> tags!), but it should work.

<div class="comments">
<h3 class="comments-head">Comments</h3>

<MTComments>
<div class="comments-body">
<$MTCommentBody$>
<p class="comments-post">Posted by <$MTCommentAuthorLink spam_protect="1"$> <$MTCommentDate$></p>
</div>
</MTComments>

<h3 class="comments-head">Pings</h3>
<p class="trackback-url">
TrackBack URL for this entry: <a href="<$MTEntryTrackbackLink$>"><$MTEntryTrackbackLink$></a> </p>

<MTPings>
<div class="trackback-body" id="p<$MTPingID$>"></a> <p class="trackback-post"><a href="<$MTPingURL$>"><$MTPingTitle$></a><br />
<b>Excerpt:</b> <$MTPingExcerpt$><br />
<b>Weblog:</b> <$MTPingBlogName$><br />
<b>Tracked:</b> <$MTPingDate$></p>
</div>
</MTPings>

</div>

I hope you don’t mind if I don’t comment exhaustively on this until much later. I had enough trouble just marking it up!