You can keep up on the latest plugin announcements and tutorials by visiting Greg's Plugins.
Please also see the README file distributed with this plugin and the plugin's main page: Greg's Comment Length Limiter plugin.
For details on how to wrap the following template tags (aka 'functions') in conditionals so your theme will only rely on this plugin when it is activated, please see the Greg's Plugins FAQ.
Under WordPress 3.0 and later, the entire comment form can be generated via a single call to the function comment_form(). If your theme uses the new comment_form, this plugin can automatically tweak the form so comments can be counted. The plugin filters the comment_field default and inserts the countdown box just after the label tag for the comment area.
The plugin is designed to allow the inserted countdown box and its accompanying text to inherit relevant styles from the theme's CSS applied to the countdown form. While this is arguably the best way of preserving the look and feel of a countdown form where we're trying in advance to accommodate thousands of differently styled comment forms with potentially vast differences in underlying coding, it does mean that if the theme hasn't fully styled the specific elements used by the countdown box and text, their rendered style may not fully match the theme. If this is the case, their visual look can be improved with the addition of extra styles specific to the elements inserted by the plugin.
For ease of styling, the box and the text description that go with it are wrapped in a span tag with the class countdownbox, while the box showing the character count is a readonly input field with the ID commentlen. So, by adding a style specific to #commentlen, or if necessary to .countdownbox #commentlen (or it can be made even more specific by tacking on a class or ID from the next level up in the comment form), it should be possible to make the box and/or accompanying text match the look and feel of the theme very closely.
If you'd really really really rather position the countdown box yourself, you can do so by tapping into the standard comment form filters and inserting the value returned by gcll_show_limit_box_for_filtering(). The function takes an optional parameter, which is the name of the class for the span which will wrap the box.
When using comment form filters to insert the limit box, also be sure to include the value returned by gcll_tweak_textarea_for_filtering within the textarea tag of your comment form -- thereby replicating the end result of following the pre-3.0 instructions below.
If your theme does not use the new 3.0 functionality, or if you would rather not have to tweak two separate comment form filters, please use the instructions in the following section.
[Brief Editorial Rant. The new comment_form is great for very minor modifications of what the WordPress coders think a comment form ought to look like, but if you want more than a couple of very minor changes, it can be even more tedious to work with than the old spaghetti mix of code and markup... Maybe one day WordPress will adopt the magic of templating, in which one specifies how something should be structured, and separate code fills in elements of that structure -- rather than adding layers upon layers of more code (i.e., filters) to modify structure and thereby deal with weaknesses of the design decision to mix code with markup in the first place.]
Preparing your comment form for length limiting is still very straightforward:
gcll_tweak_textarea()gcll_show_limit_box_manually()This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.