Count Tag Modifiers
So you have a bunch of comments, entries, TrackBacks, and other countable data… but in your template you need to have different phasing based upon if the number of comments is 0, 1, or greater than 1:
- No Comments
- 1 Comment
- 2 Comments
The solution…
Count Tag Modifiers
- none - when count is 0
- singular - when count is 1
- plural - when count greater than 1
The value of each modifier (a phrase) is returned based upon the current count value.
If the current count is desired to be part of the phrase, it must be explicitly added. A pound character “#” used in the phrase will be replaced by the current count. This is most useful for placing the count into the plural phrase. Since the none and singular phrases are only used when the count is known, the phrases don’t necessarily need to use the pound character:
- none examples
- Leave a comment
- No comments
- Be the first to comment
- singular examples
- Only 1 comment
- 1 ninja has spoken
- This post has 1 comment
- plural examples
- # comments
- OMG! # Comments
- Responses to this rant: #
If an actual pound character is desired to be part of the phrase, the pound character should be escaped with a backslash “#”.
Because the zero and plural states are often the same phrase (ie. 0 Comments, 3 Comments), the plural modifier (if present) will be used in the absence of a none modifier when the count is 0.
Usage
Choose your favorite count tag (see list below) and add the three count tag modifiers.
Let’s say you want the following three phrases:
- No Comments
- 1 Comment
- 2 Comments
You’d use this tag:
<$MTEntryCommentCount singular="1 Comment" plural="# Comments" none="No Comments"$>
Or if you want these phrases:
- 0 Comments
- 1 Comment
- 2 Comments
You can use the shorter syntax:
<$MTEntryCommentCount singular="1 Comment" plural="# Comments"$>
Movable Type Count Tags
- ArchiveCount
- AssetCount
- AssetScoreCount
- AuthorScoreCount
- AuthorEntryCount
- AuthorEntriesCount
- AuthorCommentCount
- BlogCategoryCount
- BlogCommentCount
- BlogEntryCount
- BlogPageCount
- BlogPingCount
- CategoryCommentCount
- CategoryCount
- CategoryTrackbackCount
- CommentScoreCount
- EntriesCount
- EntryCommentCount
- EntryScoreCount
- EntryTrackbackCount
- FolderCount
- PingScoreCount
- SearchResultCount
- TagCount