Hello,

I'm trying to figure out how to display the list of comments for a node in an indented threaded list
(the same way it is usually displayed in nodes).

I currently can display that list using a "comment line style" and the appropriate sort filter.
Comment threads are displayed together but my listing of comments is deseperatelly flat.

I would like to indent threaded comments, depending on their depth.

Is there a way to achieve this using "comment line style"?

Comments

RamMohanSakhamuri’s picture

In the Add relationships select comment group from relationship. In the fields you will get options for comment display for parent comments and all..

zman@vail.net’s picture

Are you referring to adding a relationship in a view? If so I do not see "comment display for parent comments". Could you give me a little more detail about this. I've been trying to get this working to set up a single user blog and I can't seem to fond the correct view settings. Thanks.

jcisio’s picture

Is this 3.x-specific or applicable to 2.x? I'd like to see this feature implemented, too. I didn't test 3.x, but in 2.8 I can't have it done :( Make the row style as Node shows the threaded comments, but it displays node teaser too.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

Views doesn't currently support a style like this. The nodecomment module has a style (specific to node comments) that can do this. It may be possible to clone this without too much work and use it on regular comments.

artscoop’s picture

Status: Fixed » Reviewed & tested by the community

Hello,

Well, even though Views doesn't support indenting comments directly, you can do this because even if you sort comments, the children are always displayed under the parent.

Example :

You have 6 comments that you will want to sort according to a value in points :
C1 (10 points)
C2 (3 points)
C3 (5 points)
C4 (15 points)
C5 (5 points)
C6 (20 points)

You want them to be sorted like this :
C6
C4
C1
C3
C2
C5

By using views alone, you will get this (no indentation) :
C6
C4
C1
C3
C2
C5

You luck is that Views uses the comment template file to render the comments.
And, in this comment.tpl.php, you can get the comment depth by using $comment->depth (it will give you a number).

With this depth, you can render a comment nested with CSS properties reflecting your comment depth.
Anf then you will be able to have you desired indentation (close to the pixel) and sorting.
It should work like a charm.

dawehner’s picture

Status: Closed (won't fix) » Active

rtbc is for patches. Move this to active.

jcisio’s picture

You can't just display threaded comment like that, because of the wrong order. How did you manage to get "if you sort comments, the children are always displayed under the parent" done?

I'll leave merlinofchaos "won't fix" this or give any new input for 3.x

merlinofchaos’s picture

Status: Active » Fixed

There's a field in the database that will properly sort comments threaded. You can sort on that and get the right order. #5 has good info in it.

artscoop’s picture

Status: Reviewed & tested by the community » Fixed

Hello,
Well, actually you can, and if you test you should see it work. I did this with Views 3.x, but this should work fine on Views 2.x too.

jcisio’s picture

Thanks, artscoop. I'll try it. I now remember that field in the comment table.

jcisio’s picture

Thanks, artscoop. I'll try it. I now remember that field in the comment table.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dagmar’s picture

I have posted a patch for this issue here: #1039494: Support threaded list of comments

chrislabeard’s picture

I haven't checked out the patch but found another solution that seems to work for what I need. This for all I know might be fixed in views now and I might just not be doing it correctly. Anyways this code works great for me. Basically it just repeats the indented div based on the depth of the comment.

<?php echo str_repeat("<div class='indented'>", $comment->depth);?>
<article class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' '. $status; print ' '. $zebra; ?> clearfix">

  <header>
    <?php print $picture ?>

    <h3><?php print $title ?></h3>

    <span class="submitted"><?php print $submitted; ?></span>

    <?php if ($comment->new) : ?>
      <span class="new"><?php print $new ?></span>
    <?php endif; ?>
  </header>

  <div class="content">
    <?php print $content ?>
    <?php print $comment->depth; ?>
    <?php if ($signature): ?>
      <div class="user-signature clearfix">
        <?php print $signature ?>
      </div>
    <?php endif; ?>
  </div>

  <?php if ($links): ?>
    <footer>
      <?php print $links ?>
    </footer>
  <?php endif; ?>

</article> <!-- /.comment -->
<?php echo str_repeat("</div>", $comment->depth);?>
pyxio’s picture

Hi Chris,

I need to created an indented views comment thread, where does this code go? I think views will override this, no? Cheers Kevin

pyxio’s picture

nevermind, i found it. i did not realize views uses standard drupal templates. anyway, i still can't get it work. the problem may be that the who comment is displayed using a views rewrite.

rschwab’s picture

Issue summary: View changes

This worked for me:

  1. Add a field to the view, Comment Depth. Exclude it from display.
  2. Rewrite one of your fields to include the depth as a class you can target with css.
  3. For example, mine was on the author picture: <div class="comment-depth-[thread]">[picture]</div>
  4. Add the css in your theme, ex: .comment-depth-1 { margin-left:50px;}
  5. Add a sort criteria: Comment: thread (asc)