Download
Questions, Bugs, Enhancements? Mail me: yatcp@organisiert.net
Features
- Tested from WP 2.0.10, up to 2.5
- Out of the Box threaded comments
- Works without Javascript
- Customizable through CSS or own templates
- Completely internationalized for easy translation
- Limiting of nesting depth
- GPL v2 licensed
Template Customization
To work out of the Box YATCP comes with it's own template Files. Nevertheless you are free to replace them with your own, in order to provide maximum flexibility. The Template consists of two Files: yatcp_comments.php which creates the outer frame for the comment List. It is used to display all the things that belong to the comments but are not comments, as the Heading ('$n comments') and the comment form.
Second to that is yatcp_single-comment.php which handles the display of the nested lists of comments. Most important in that piece of PHP is that it recurses over the Comments (otherwise it wouldn't display any nesting). Also the look of each single comment is created in here. Based on the configured maximum comment depth and the current comment depth the recursion is done or not, so the different display is solved in a single file.
Again, there is more than one way you could influence the display of comments by supplying Template Files of your own.
Changing only the Comments List
When you like the outer frame and don't want to change it, you could simply replace the yatcp_single-comment.php by supplying a file named single-comment.php in your Template Directory. YATCP will look for that file automatically and include it instead of it's own, when it is provided.
You might get some inspiration of how things are done by looking at the included yatcp_single-comment.php but I try to mention the most important parts here:
- For recursion you have to call yatcp_show_comments($comment); at an appropriate place in your Template File
- The checking whether the comments may nest deeper is not done in the template but is located in yatcp_show_comments instead, so you do not worry about that in your template
- Threaded replies are loaded before single-comment.php is included. These are stored in $cmts[]
- $cmts is an associative Array used to store the different nested answers so they don't get lost while recursing
- $cmt_ID is the ID of the Parent of the currently displayed Comments. When it is 0 the parent is the Post itself
- Taking the both points above in account your Template should always iterate over $cmts[$cmt_ID]
- yatcp_find_comments($comment) can be used to see if a comment has any children (test if count() of the result equals to 0)
Changing all comment Template Files
In addition to supplying your own single-comment.php you might also replace the yatcp_comments.php with your own template if you need to. For that simply supply a File named yatcp_comments.php in your template Directory, or replace the call yatcp_comments_template() in your Template with yatcp_comments_template('/$your_template_file'). Make sure to include the leading "/". YATCP will then look for that File in your Template Directory and include if it is found there.
Again the included yatcp_comments.php might serve an a source for inspiration in addition to the following important points:
- Make sure to include a call for yatcp_show_comments() (no argument!). This includes your (or the standard) single-comment.php. Omitting the argument to that call makes YATCP load the "first level" comments, which are replying to the post itself.
- When showing the Comment Form, make sure to include the following action hook:
<?php do_action('comment_form', $post->ID); ?>, which is used by YATCP to include the Dropdown-Select for choosing the Reply to. Otherwise you might include the Template call yatcp_show_comment_parents($post_ID) which does the same.