(This post dedicated to frequent Winds reader "lurker", who inspired me to keep trying... unfortunately, while it worked for a couple of days, it stopped working shortly thereafter for reasons that are unclear.)
We've had ongoing issues on Winds with our "Recent Comments" sidebar item widening massively and blowing up the main page layout when URLs are used too soon. It has been driving me batty for months - but I think I may have fixed it today.
Here's how it was done - and while I'm at it, I'll also offer a short tutorial on how to do something amazingly useful that will really cut your template maintenance work: PHP Includes.
Here's what I did: Short Version
Actually, I tried everything. In the end, the key was deceptively simple - and I'm still not sure why it works. Maybe MT tag modifiers don't interpret stuff in URL tags. Anyway, reversing 2 items did it. From:
[$MTCommentBody remove_html="1" trim_to="100" $]
To:
[$MTCommentBody trim_to="100" remove_html="1" $]
In other words, trim excerpt length to a designated number of characters first. Then specify HTML removal.
Here's what I did: Full Details
First, before beginning the experiment, I created an include in our templates. We use them so we can have elements that change in one shot across every one of our templates: Main Page, Individual posts, Posts by month, etc.
- Go to templates in your MT Admin. console.
- Click on the "Create new index template" link.
- Template Name = "Includes: Recent Comments" Note the 2-stage name, which helps us organize our templates by type (thanks, Evariste).
- Output File = "includes/recent-comments.inc" Again, this is for organization.
- Add this template body:
Note that I've replaced > and < with ] and [ so you can see the template body. I've also added comments behind /// - you'd remove them if using this code and convert the [].
[div class="sidetitle"]Recent Comments[/div]/// puts "Recent Comments" in sidebar title formatting, as defined in our site's CSS style sheet.
[div class="side"]/// puts everything that follos in sidebar text formatting, as defined in our site's CSS style sheet.
[br] Read [a href="http://www.windsofchange.net/archives/003367.php"]our comments policy[/a].[br] [br] [MTComments lastn="5"]/// Link to our comments policy, then take the site's last 5 comments and displays them
[MTCommentEntry]/// Tag to display each of the comment entries, but unless modified, it will display the WHOLE entry. So we add a format and limits:
[$MTCommentAuthorLink spam_protect="1" $]: [$MTCommentBody trim_to="100" remove_html="1" $]... [[a href="[$MTEntryLink$]#[$MTCommentID$]"]go[/a]][/MTCommentEntry]///$MTCommentAuthorLink displays the author and a link to their web site, or email if no site is entered. If you do display the email, spam_protect="1" modifies it so spambots can't harvest it but browsers can still decode it.
/// $MTCommentBody trim_to="100" remove_html="1" takes the comment, trims it to the 1st 100 chartacters, then strips out any HTML. Some comments will be very short as a result, but your layout problem is gone. Then add the "..." so people can see there's more.
/// $MTEntryLink$ is the blog post link. "#" is the anchor symbol for URLs wtithin a page. And $MTCommentID$ links to our use of that tag in the Individual Archive template, where we insert [a name="[$MTCommentID$]"][/a] in the top line of each comment. That way, you can jump to individual comments.
/// Then we end that comment entry
[br] [br]/// We create separation between each entry. By putting the tags here, they'll be added after each comment excerpt as the server keeps inserting them until "n" is reached (5, in our case).
[/MTComments]/// Now we stop the MTComments process once "n" is reached.
[/div]/// Having stopped that segment, we end the formatting so everything is clear for the next Sidebar title.
[br] [br]/// Adds separation before the next sidebar module... remember, this is an include. I always put the end separation inside my includes so it's consistent throughout all templates if I decide to change it, but you can choose to have it in each template instead.
FYI, all this goes in your templates with a simple one-line PHP include. Note that it only works if you've set the suffix for all your MT pages to ".php" in the "Weblog Config" section. Again, we've replaced > with ]:
[?php include("LocalSitePathValue/includes/recent-comments.inc"); ?]
The Local Site Path can be cut and pasted from your "Weblog Config" screen. Note, too, the use of round brackets inside for the include location - don't replace them.
Hope this helps others avoid the pain we went through, and maybe even helps some folks kick their blogs up another notch....








I'm grateful for and to humanity's heroes, and the people who achieve.
MSNBC is a news Web site. There how does that look? Is it OK? Golly! I hope so!
Yea! It looks like it's working. Is it really?
Test of linking shortcut. My previous tests directly using HTML seemed to work. The above link uses the WoC shortcut.
We use similar code at Discarded Lies. However, the requirement that MT rebuild the recent comments include was just too weird as an experience for the user. A reader would post a comment, the thread would reload, and MT would still be rebuilding the include in the background, so the recent comments sidebar would not include their newest comment. Then, the next time they reloaded, it would be there. Winds of Change doesn't have this problem because you're not showing the recent comments in the sidebar of an individual entry, so by the time a reader returns to the front page, their comment will already have appeared in "recent comments".
Instead, we went to dynamic php pulling the recent comments live from the database, to avoid the rebuild lag. Here's some code, simplified from what we actually use:
As you can see, it's a dramatic amount of code to duplicate what MT gives us with a few simple tags and attributes. But it's worth it for us, because the user doesn't have an incongruous experience when their newest comment doesn't show up in the recent comments immediately, and we can show emphasis that might be lost in a text-only comment preview. I omitted code that also shows if the commenter has posted an image, or if certain words are a link, etc-trying to fit as much useful information into the comment previewer in a visually attractive and non-jarring way as possible. That looks like a lot of code but it actually executes in milliseconds so there's no perceptible difference in pageload times. You can see it live in action at Discarded Lies.I'm puzzled why Joe's technique is working. As near as I can tell, remove_html does what it says - it removes HTML. But a URL is not HTML, it's a URL. And URLs are the long strings that cause these problems.
I manage a site that has been using a technique almost identical to the one Joe describes for several years. It works nicely in every way except for the fact that long URLs in comments still cause problems in sidebars for IE users.
I'm looking for a solution that will actually remove URLs. Any suggestions?
For whatever reason (note test comments above, which worked), it no longer works. It doesn't matter whether the URLs are hard-coded as HTML in the comment box, or attached via Textile coding that then gets converted. In both cases, not only does the URL show up but so does the HTML coding.
This says to me that we have a simple problem called "the Movable Type tag is badly coded and doesn't work". A well coded solution would indeed strip all HTML coding formats and items enclose in the > and < out of the text, which would erase the URL strings as well as the HTML tags while leaving the transformed text untouched.
The cure sits in Six Apart. Unless there's a way to fix their bad coding through a plug-in that wouldn't have other undesirable effects.
I think the important distinction is that when a URL is in an href, it's HTML. But when a user just pastes in a URL and it's not part of a link, it's just a string like any other.
What complicates things, I think, is the "Auto-link URLs in comments" setting. Yes, it links the URL, but it links it to itself, i.e. one URL in an href and one as a string. I'm betting that if that option allowed MT to just create a link that said [link] or similar, the problem might go away. Not sure.
I've posted this question on the MT support forum as well [link] :)