Scroll
Views で複数値フィールドを使用したときのノードの重複を取り除く方法
最近、Views を通じて会社のリストを出力していたのですが、なぜか Views が同じレコードを 1〜3 件ずつ出力していて、かなり奇妙でした。フィルターやソートを削除してみましたが、それでも重複します。問題は、ノードが複数値の日付フィールドを持っていたことです。そしてこれらの会社ノードが重複していました。以下は私の、そしておそらくあなたの 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 のページディスプレイの名前です。この挿入の後、view でノードは重複しなくなりました。
これは英語の解決策で、この問題の他の解決策もここで見つけました。