Textpattern CMS‘s comment infrastructure is basic but functional. Textpattern tags are used to construct forms that comment authors can use to leave feedback, and there are a bunch of other comment-specific tags used to sort and display said comments after they’ve been approved (moderated):
Most of these are pretty straightforward to understand from the tag name, especially if you’ve been using Textpattern for a while and understand the nuances of the project developers, but here’s the scoop on each one.
Starting with `comment_anchor`, as good a place as any to begin, this is arguably the simples of the list: no attributes to play with, it just outputs an anchor for a specific comment, like this:
Note two things: first, it’s not an absolute hyperlink to the comment, it’s just a page anchor, and second that the comment anchor is a number. The first comment on any Textpattern installation has a `comment_id` of 1, or 000001 in long form. The next comment will be 2 (or 000002), then 3, and so on. The `comment_id` is always a number, and the `comment_anchor` always begins with `c`. With that in mind, the `comment_permlink` is an absolute URL to the comment in question, like this:
Note the #000123 at the end. That’s the anchor to the location on the page itself. Neat, huh?
Moving on. The `comment_time` tag outputs the date and/or time the comment was authored/submitted, regardless of when it was moderated or approved. It has a few attributes to fine-tune the date format:
- format=”value” (override the date format as set in the preferences)
- gmt=”boolean” (local time, or GMT value)
- lang=”ISO language code” (ISO 639 date format)
The date format follows that of `posted` and `modified`, too, so if you’re a pro at those you’ll have no bother with comment date formatting.
The oddly-named `comments` tag is simply to start outputting the comment(s) associated with an article. This differs from the `comment_*` tags in this list because it typically resides in an article form, whereas `comment_*` tags live in a comment form. Think of `comments` as being the trigger for an article to start dipping into its comments on the rendered page. The next tag in the list is `comments_count`, which is another article form dweller. It outputs the number of comments, if any, that an article has. No attributes, just a number. Simple, but useful.
The `comments_invite` tag is, as you may already have figured out, used to output the ‘hey, leave me a comment – please!’ text. You can use a few attributes with this sucker to tweak the output, too:
- class=”class name” (CSS class name, default is `comments_invite`)
- showalways=”boolean” (display the invite all the time, regardless of comments status)
- showcount=”boolean” (show the count, or not)
- textonly=”boolean” (show the invite as plain text, or a hyperlink)
- wraptag=”tag” (what to wrap the comments invite in)
I mentioned in a previous article that Textpattern comments need to be previewed before they are submitted, and this tag is the trigger for said comment preview. Three attributes for your delight:
- class=”class name” (CSS class name, default is comments_preview)
- form=”value” (specify which form should be used)
- wraptag=”tag” (tag to wrap the preview in)
The last tag, `recent_comments` outputs a list of – erm – recent comments in this format:
Commenter’s name (Article title)
This is useful in an aside or footer if you want links to the most recent comments. A few attributes are available, should you wish to change the formatting:
- form=”form name” (pick your form)
- limit=”integer” (how many items in the list)
- offset=”integer” (how many comments to skip from the most recent.
- sort=”sort value(s)” (how to sort the list – all kinds of fun with this one)
This tag typically lives in a page, rather than an article or comment form.
Next time: conditional comment tags. See you then.