0

我在这里提出一个讨厌的问题。

Drupal 处理注释让用户可以选择以 4 种方式显示它们:Flat list - collapsedFlat list - expandedThreaded list - collapsedThreaded list - expanded.

我使用最后一个,它提供了如下标记:

<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>

但我希望在“父”注释的同一个 dom 元素中包含“子”注释。因此,例如,类似:

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

为了有一个标记,允许我像这个博客(使用 wordpress)那样显示线程评论。

它使用如下标记:

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

那么,drupalish的方法是什么(如果我需要的所有更改都在 template.php 或模板文件中会更好)?

4

1 回答 1

1

comment_render()似乎在内部做所有事情。所以你需要重写这个。不幸的是,如果您使用node_show()来渲染节点,comment_render 将自动运行(而不是通过可覆盖的主题函数),因此您需要做很多工作才能让它做您想做的事情。

首先,您必须使用hook_nodeapi来说服 drupal 核心没有评论(谈话模块这样做)

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;
  }
}

然后,您将需要编写自己的 comment_render 实现(带有嵌套)并在节点渲染后调用它(可能在您的模板页面或预处理函数中)。

于 2010-01-14T14:57:29.227 回答