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:
<br />
<MTEntryIfComments count_equals="0">No comments</MTEntryIfComments><br />
<MTEntryIfComments count_equals="1">1 comment</MTEntryIfComments><br />
<MTEntryIfComments count_greater_than="1"><MTEntryCommentCount> comments</MTEntryIfComments><br />
Example: To enclose a list of comments with a div tag only if the list is empty:
<br />
<MTEntryIfComments><br />
<div class="comment-block"><br />
<MTComments><br />
<div class="comments-body"><br />
<$MTCommentBody$><br />
</div><br />
</MTComments><br />
</div><br />
</MTEntryIfComments><br />
If two comments are present, this will generate:
<br />
<div class="comment-block"><br />
<div class="comments-body"><br />
<p>This is a comment</p><br />
</div><br />
<div class="comments-body"><br />
<p>This is another comment</p><br />
</div><br />
</div><br />
If there are no comments present, nothing, not even the <div class=”comment-block”> tags won’t be generated.