logo

额外区块类型 (EBT) - 全新的布局构建器体验❗

额外区块类型 (EBT) - 样式化、可定制的区块类型:幻灯片、标签页、卡片、手风琴等更多类型。内置背景、DOM Box、JavaScript 插件的设置。立即体验布局构建的未来。

演示 EBT 模块 下载 EBT 模块

❗额外段落类型 (EPT) - 全新的 Paragraphs 体验

额外段落类型 (EPT) - 类似的基于 Paragraph 的模块集合。

演示 EPT 模块 滚动

滚动

Views:当使用多值字段时如何去除节点重复显示

11/10/2025, by Ivan

最近我在使用 Views 输出公司列表时,发现 Views 会重复显示 1–3 条相同的记录,这让我很困惑。尝试删除过滤器和排序条件后,问题依然存在 —— 节点仍然重复。原来问题出在节点包含了一个具有多值的日期字段(multi-value field),正是这个字段导致了公司节点的重复。下面是我解决 Views 节点重复 问题的方法,或许也能帮到你:

首先创建一个自定义模块,我将它命名为 sitemade。文件 sitemade.info 的内容如下:

name = Views Remove Duplicates
description = Removes duplicate nodes. Requires editing the module file 
to identify the views you want to affect.
package = "Views"
core = 6.x
dependencies[] = views

然后创建文件 sitemade.module,内容如下:

<?php
function sitemade_views_pre_render(&$view){
  $used_nids = array();
  if ($view->name == 'companies'){
    if ($view->current_display == 'page_1'){
      foreach ($view->result as $row){
        if (!in_array($row->nid, $used_nids)){
          $new_view_result[] = $row;
          $used_nids[] = $row->nid;
        }
      }   
      $view->result = $new_view_result;
    }
  }
}

其中 'companies' 是我的 View 名称,而 'page_1' 是该 View 的页面显示(display)名称。添加这段代码后,节点在 Views 中就不会重复显示了。

我在以下英文文章中找到了这个解决方案以及其他类似问题的处理方法:

http://capellic.com/blog/cure-duplicate-nodes-in-a-view