movabletype评论隔行换色
很早之前有过一篇日志说了一种很笨的实现评论隔行换色的方法这里。今天说一种比较“高级”的实现方法。
MovableType 4的模板标签新增了很多内容,有一些是鲜为人知的。比如有四个变量:“__even__” “ __odd__” “__first__” “__last__"。(注意,只是引号内的内容,不包含引号。)
这些变量可以被用在<MTIf>标签里,分别用于判断文章或者评论列表里的项目是否是列表中的偶数项、奇数项、第一项、最末项。
以MovableType默认的评论列表模板举例,具体运用在实现评论隔行换色的时候,可以在模板里设置如下:
<div class="comment<MTIf name="__even__"> even<mt:else> odd</MTIf>"<MTIfArchiveTypeEnabled archive_type="Individual"> id="comment-<$MTCommentID$>"</MTIfArchiveTypeEnabled>>
<div class="inner">
<div class="comment-header">
<$MTCommentAuthorLink default_name="Anonymous" show_email="0"$> <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> said:
</div>
<div class="comment-content">
<$MTCommentBody$>
</div>
<div class="comment-footer">
<a href="#comment-<$MTCommentID$>" title="Permalink to this comment"><$MTCommentDate format="%x %X"$></a>
</div>
</div>
</div>
其中的绿色内容是需要添加的,意思是如果该条评论在评论列表里是第偶数条就给这条评论的包裹框加上一个even类,否则归为odd类。然后即可在css文件里对even和odd类分别定义样式,很容易即可实现隔行换色了。效果见本站。
PS.换回了movabletype,始终还是觉得静态的页面比较踏实。不过说实话,Textpattern的确是很帅气的程序。我还会继续在其他地方应用它。
发表评论