Limiting indentations for threaded comments in Drupal

Drupal

(This works for Drupal 5.x, 6.x, 7.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.

Main post
Simulated main post to which comments have been added.
First comment. No indentation here yet.
Second comment, first indentation.
Third comment, second indentation.
Fourth comment, third indentation.
Fifth comment, fourth indentation.
Sixth comment, fifth indentation.
Seventh comment, no further indentations.
Eighth comment, no further indentations.

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, with 5 indentations, 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.

Comments

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 the comments section; you will want to change the default display order.

— Stephan

Nice solution,I tested this i drupal 7 and it worked well.

Yes, since it's CSS it only depends on the theme you're using really.

Here's a solution of mine that works with any level of indentation :-) as long as the discussion doesn't branch of to much.

At StackExchange: http://ux.stackexchange.com/a/40908/12969
A blog post I wrote: http://www.debiki.com/-01jn7-solving-problem-nested-replies-indentation

Now this would be very complicated, but it's open source (Javasript + Scala) so theoretically you could copy some code and use in a Drupal plugin.

Granted, my solution is really Drupal only, although it would depend on how it the indentation is achieved. I am going to take a closer look at your solution, thanks for posting it.