Limiting indentations for threaded comments in Drupal
stplanken — January 28, 2009 - 19:32

(This works for Drupal 5.x and 6.x.)
Threaded comments in Drupal are fine, but after a certain number of replies, you really need to limit the amount of indentation or the comment space will get too small to be useful.
At first, I hacked the comment module and added a variable to define the maximum number of nested comments. Since I am drastically reducing the number of hacks in favor of more appropriate solutions, I decided to solve this with CSS.
Take a look at the result. In comments, the left indentation (margin-left) is taken from comment.css.
Simulated main post to which comments have been added.
By default, comment.css defines the left margin for each indentation:
/* Default from comment.css */
.indented {
margin-left: 25px;
}To limit the maximum number of indentations, I added the following to the theme style sheet:
/* Limit max nbr of indentations */
.indented .indented .indented .indented .indented .indented {
margin-left: 0;
}
The maximum level of nested comments in this example is 6, so the class is repeated that many times. This works regardless of the actual number of nested comments. Perhaps not the most elegant solution, but it is easy to implement.
Nice ! Thanks !
You're welcome.
Thanks, from me too. Fixes a major annoyance.
Good! I am still using this in my CSS myself too, although on this site I switched to flat comments.
Hello, Do you know how to change the way threaded comments are displayed? Cos when I post a threaded comment it comes on top instead of on the bottom. Which is very annoying. Is there a way to do this?
You can change that via
/admin/content/node-type, then select the node type you wish to modify the comments for. Look at thecommentssection; you will want to change thedefault display order.— Stephan
Post new comment