MTEntryIfComments 2.0
January 8, 2003
- updated February 8, 2006
(Download)
MovableType has conditional tags that are true when entries and pings are enabled. The following tags allow you to test whether comments or pings exist.
- MTEntryIfComments
A conditional tag that is true if the current entry has one or more (or a specific number of) comments. Useful if you want to add content before/after a list of comments only if the list is not empty, or if you want to display different text based on the number of comments.
The tag supports the following attributes:
- count_greater_than=”n”
Condition is true if the entry has more than n comments. The default value is count_greater_than=”0”
- count_less_than=”n”
Condition is true if the entry has fewer than n comments. Overrides the count_greater_than attribute.
- count_equals=”n”
Condition is true if the entry has exactly n comments. Overrides the count_less_than attribute.
- MTEntryIfPings
A conditional tag that is true if the current entry has one or more (or a specific number of) pings.
This tag supports the same attributes as MTEntryIfComments.
- MTEntryIfCommentsPings
A conditional tag that is true if the current entry has one or more (or a specific number of) pings and comments.
This tag supports the same attributes as MTEntryIfComments.
Examples
Example: To display “No comments”, “1 comment” or “x comments” based on the number of comments:
<MTEntryIfComments count_equals="0">No comments</MTEntryIfComments>
<MTEntryIfComments count_equals="1">1 comment</MTEntryIfComments>
<MTEntryIfComments count_greater_than="1"><MTEntryCommentCount> comments</MTEntryIfComments>
Example: To enclose a list of comments with a div tag only if the list is empty:
<MTEntryIfComments>
<div class="comment-block">
<MTComments>
<div class="comments-body">
<$MTCommentBody$>
</div>
</MTComments>
</div>
</MTEntryIfComments>
If two comments are present, this will generate:
<div class="comment-block">
<div class="comments-body">
<p>This is a comment</p>
</div>
<div class="comments-body">
<p>This is another comment</p>
</div>
</div>
If there are no comments present, nothing, not even the <div class=”comment-block”> tags won’t be generated.