Recently in MT Style Tweaks Category

Alternating Comment Styles with Smarty

| No Comments

[TESTING]

So you want to create alternating background colors for your (dynamically published) comments? I just came across a sweet little *gem in Hacking Movable Type about Smarty's "cycle" function... worth the price of the book, IMO. But, I digress. :-)

If you are using dynamic publishing for your individual entry archives, you can very simply edit your template to create alternating comment background colors (or any alternating style) with Smarty's "cycle" function.

The "cycle" funtion will, as the name implies, cycle through a list of values each time it is used within a loop. This is a perfect little solution for the task at hand. An added bonus is that it can cycle through more than two values, allowing you to alternate two, three or more styles. In MT's dynamic archives templates, the smarty cycle tag is written with double brackets {{cycle values="x,y,z"}}, using whatever values you want (numerals, words, etc). Here is one way to use it in your (MT3.2) individual entry archive template:

3-column archive templates

1)  copy main index template from

<div id=container>
to
<div class=content>
2)  in individual archive template paste (what you just copied above), replacing from
<div id=container>
to
<div class=content>
3)  cut
<br style="clear: both;" />
from beneath/end of "FORGET INFO" code and paste
<br style="clear: both;" />
under/at end of (FINISH THIS THOUGHT! brain fart... sorry!)

That is all fine and dandy as long as you have comments open. If comments are closed you need to clear the floats or your 3 columns will be differing lengths. Not a pretty sight! So...
4)  paste this code:

<MTElse> <br style="clear: both;" /> </MTElse>

just above these closing tags near bottom of page (using tags for 3.1x or earlier):

</MTEntryIfCommentsOpen> </MTEntryIfAllowComments>

or if you're using 3.2 tags clear goes BETWEEN these tags like this:

</MTIfCommentsActive> <MTElse> <br style="clear: both;" /> </MTElse> </MTIfCommentsAccepted>

This is what worked for me. Hope it works for you.

input styles

* this style requires small hack to mt's search_templates search field in form: input id="search" */

.content form input#search { background-color: #fcebd8; }
.link-note form input#search { background-color: #fcebd8; }
.link-note form input#input { background-color: #fcebd8; }

displaying code in entries

There are several ways to suitably display code in MT entries. If you do not encode your code (replace html entities) it will become the very code you're attempting to display. (out of espresso beans this morning, brain is fuzzy, sorry for the convoluted verbiage)

Rather than doing the "textarea" thing (google for more info on that), I prefer to simply run the code through a web utility that replaces the html entities so my code will display properly. I then surround my newly encoded code with blockquote tags and I'm done.

There are numerous free encoding tools on the web. My favorite (because I could install it on my own site) is SimpleCode by Dan at SimpleBits. You might also check out

On a quest to style comments with alternating background colors (or any style) I chose to employ Adam Kalsey's MT-SimpleComments (w/PHPSimpleComments) plugin. The main feature of this plugin is to integrate trackbacks and comments into one seamless list and provide a unified count of comments and pings together. It also adds the handy dandy <MTSimpleCommentsOdd> tag which specifies 1 for odd- and 0 for even-numbered comments (thus allowing for alternating comment styles). Not that I have a real need for any of that because 1) nobody reads my blogs and 2) even if someone did they'd probably never ping me and again 3) even if they did and left a comment there are unlikely to be THREE comments on any given entry which is what it would take to see the coolness of the alternate styling. BUT, I am SO over that. It is the exercise in plugin and template tweaking that holds the real value for me! :-)

There's always a glitch in the matrix, though, and for me (this time!) it is that v1.32 function.MTSimpleCommentCount.php does not work outside the <MTSimpleComments> tag like it should. To display a unified comment count, I had to use the file from v1.31 available here from the guy who did the first php port of this plugin. I haven't found anyone else with this problem, so perhaps it's just user error. I would be glad to receive any suggestions on this.

Here are the details on how I implemented this plugin both for integration and alternating comment styles on my own sites...

Typekey Commenters Icon

You may have noticed that commenters with Typekey identities display a hyperlinked image beside their names: nav-commenters-grind.gif This icon, which is used to signify commenters authenticated via Typekey, is copied to your blog directory when you first publish your blog.

If you like to keep things pretty, you might want to replace the original image (a dark charcoal color... so utilitarian) with one that is color coordinated with your site. Customizing nav-commenters.gif to coordinate with your blog's style is a snap.

How? you ask...

About this Archive

This page is an archive of recent entries in the MT Style Tweaks category.

MT Source Hacks is the previous category.

MT Template Tags is the next category.

Find recent content on the main index or look in the archives to find all content.