Alternating comment colouring in MT without PHP

Using my Switch plugin you can create alternating background colors for comments. The technique is quite simple.

First, set this somewhere near the top of your index template (before any comments):

<MTSetVar name="oddevencomment" value="evencomment">

Then, modify the MTComments section of your individual entry archive, so that the value is alternated.

<MTComments>
<MTSwitch value="[MTGetVar name='oddevencomment']">
<MTSwCase value="evencomment">
<MTSetVar name="oddevencomment" value="oddcomment">
</MTSwCase>
<MTSwDefault>
<MTSetVar name="oddevencomment" value="evencomment">
</MTSwDefault>
</MTSwitch>
<div class="<MTGetVar name="oddevencomment">">
<h3><$MTCommentAuthor$> said:</h3>
<$MTCommentBody$>
</div>
</MTComments>

Please note that the MTSwitch tags do not strip whitespace, so you might want to remove any superfluous newlines and spaces inside this tag.

Finally, you can go on to modify your CSS, so that every odd and even comment gets alternating colour:

div.oddcomment { background: #ccc; }
div.evencomment { background: #fff; }

Enjoy!

Comments

Comment from Shannon on 2005-10-31 14:25

Hey,

Thanks so much - this was fast, easy and works really well. I’m not a programmer, and was able to implement alternating backgrounds on my comments with ease.

One question: Can I set a third variable with a different background? I’d like to have alternating comments, but a separate background for myself when I decide to add a comment of my own.

Thanks again. :D
Shannon

This discussion has been closed. No further comments may be added.