开发者

Changing the threading comments markup in Drupal 6

开发者 https://www.devze.com 2022-12-17 11:37 出处:网络
im here with a nasty question. Drupal handle comments giving the user the choice to display thems just in 4 ways: Flat list - collapsed, Flat list - expanded, Threaded list - collapsed, and Threaded

im here with a nasty question.

Drupal handle comments giving the user the choice to display thems just in 4 ways: Flat list - collapsed, Flat list - expanded, Threaded list - collapsed, and Threaded list - expanded.

Im using the last one, whom provide a markup like:

<div class="comment">
    <!-- comment's content -->
</div>
<div class="indented">
    <!-- next comment is an 'answer' to the previous comment! -->
    <div class="comment">
        <!-- comment's content -->
    </div>
</div>

But i would like to have the 'children' comment inside the same dom element of the 'parent' comment. So, for example, something like:

<div class="comment">
    <!-- comment's content -->
    <div cla开发者_高级运维ss="indented">
        <!-- next comment is an 'answer' to the previous comment! -->
        <div class="comment">
            <!-- comment's content -->
        </div>
    </div>
</div>

in order to have a markup that allow me to show the threaded comments as this blog (using wordpress) does.

It use a markup like:

<ul>
    <li>
        <div class="comment>
            <!-- comment's content -->
        </div>
        <ul class="children">
            <li>
                <div class="comment>
                    <!-- comment's content -->
                </div>
            </li>
        </ul>
    </li>
</ul>

So, what is the drupalish way to do that (better if all the changes i need are in the template.php or templating files)?


comment_render() seems to do everything internally. So you would need to rewrite this. Unfortunatly if you are using node_show() to render your nodes comment_render will be run automatically (not via an overridable theme function) so you will need to do quite a lot of work to get this to do what you want.

Firstly you will have to use hook_nodeapi to convince drupal core that there are no comments (the talk module does this)

function talk_nodeapi(&$node, $op) {
  switch ($op) {
    case 'load':
      if (talk_activated($node->type) && arg(0) == 'node' && !arg(2)) {
        // Overwrite setting of comment module and set comments for this node to disabled.
        // This prevents the comments of being displayed.
        $output['comment_original_value'] = $node->comment;
        $output['comment'] = 0;
        return $output;
      }
      break;
  }
}

Then you will need write your own implementation of comment_render (with nesting) and call that after the node is rendered (probably on your template page or in a preprocess function).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号