Hello,

I have a "See Also" block that appears on all my nodes of type page (except the front page). This is created with Views. I use a list view. The only field I include is the node title. For Arguments, I have Taxonomy: Term ID set to Display All Values. Then, there's argument code that gets the taxonomy of the page the block appears on and passes it as an argument:

$tids = '';
if($type == 'block' && arg(0) == 'node' && is_numeric(arg(1) ) ){
  //$vid = 2; // this is the vocabulary id to search through...
  //$terms = taxonomy_node_get_terms_by_vocabulary(arg(1), $vid);
  $nid = (int)arg(1);
  $terms = taxonomy_node_get_terms($nid);
  foreach($terms as $term){
    $tids[] = $term->tid;
  }
  $tids = implode('+', $tids);
}
return array($tids);

I filter on nodes of type "Page". I also configure the resulting block not to show on generated pages (e.g. other views, admin and edit pages, etc.) because otherwise I get an error, since these pages have no taxonomy tags. I should add an if statement to check to see if there are any tids before the implode line, because on a page without taxonomy tags, this generates an error otherwise. I haven't had a chance to make this correction yet.

What this does is cause a block to appear on every page that lists links to other pages that have the same taxonomy. And it almost works correctly.

However, there is an annoying bug: I get multiple listings of the same pages if there are multiple taxonomy terms that the pages have in common. For example, I am administering a website for a college. I have a taxonomy vocabulary that describes departments, and also a vocabulary for different audiences, e.g. prospective students, current students, etc. Suppose one of my departments has special admission requirements. Then I want to add the taxonomy term for that department and also for prospective students. Now suppose there is also a special orientation event that the department holds for prospective students. I tag that page with both the department and prospective students. Now, on the department page, these two pages will show up in the links block, and on the prospective students page these two pages likewise show up. But if you are on the special requirements page, both the special requirements page and the orientation page will show up TWICE. I haven't figured out how to solve this yet. It seems to me that the view should only return each page once, since it does an AND between filters, but clearly something in the arguments code isn't working the way I think it does.

You should be able to see an example of this problem here: http://132.177.95.125/apache2-default/drupal-5.1/BS_Bus_Admin

This page has 2 taxonomy tags, and the page itself shows in the "See Also..." block 2 times, and several other pages that have both tags also show up in the list twice. What can I do to eliminate this duplication, other than only use one tag per page? I would still like to show all pages that match all taxonomy terms, so it's not that I want to force the terms to be ANDed together, but I don't want to see overlapping pages more than once.

Thanks

Comments

Answer: Add a filter on node:distinct.

Status:Active» Closed (fixed)

I had the same issue and emdalton's advice really helps. As the author doesn't respond, I think we can close it.

Component:User interface» Views Data
Status:Closed (fixed)» Active

Hi,
I have been trying unsuccessfully to create a taxonomy block based on views. I wanted to create a block that lists nodes that matches a couple of different taxonomy terms. When I create the view the resulting block inevitably has duplicates unless I select the "Is All Of" operator in which case it works fine. I finally gave up on this after having tried different options and settled with Taxonomy block which allows you to create a block for a term in a taxonomy. But I feel that this is the domain of views. I tried the distinct option and like discussed in several different posts I tried the "delete filters create again" and "delete view create again" "add distinct option first" alternative strategies. None worked. The site is http://www.zyxware.com. I wanted the view for both the pricelists block and the Linux and ubuntu block. Currently the pricelist block is a view with "Is All off" selected while the Linux block is a taxonomy block.
Cheers
Anoop

is it possible to hide the node:distinct filter from the users.

I believe I had the same problem than yours.

Tracing the source code behaviour, I found DB queries are properly set so you have:
$total_rows which value defines the number of distinct nodes
and
$num_rows which value defines the number of "duplicated" nodes.

unfortunately, I was no able to figure out how those two arguments are used in the code (it seems they are not used).

So I did the following modification in views.module:
!!!! THIS WORKS FOR TEASER & NODE DISPLAY, the same modification would have to be done in theme_views_view_list for LIST display

MODIFIED FUNCTION:
/**
* Display the nodes of a view as plain nodes.
*/
function theme_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {

if ($view->total_rows != $view->num_rows) { // IF statement to handle the case where there are duplicated nodes
$nid_distinct = array(); // Setup an array to hold nid that as already been processed
foreach ($nodes as $n) {
if (!in_array($n->nid, $nid_distinct)) { // Do something ONLY IF if that nid as never been processed
$nid_distinct[] = $n->nid; // Add that nid in the "reference array" because we are processing it
$node = node_load($n->nid);
$output .= node_view($node, $teasers, false, $links);
}
}
} else {
foreach ($nodes as $n) { // use initial code elsewhere
$node = node_load($n->nid);
$output .= node_view($node, $teasers, false, $links);
}
}
return $output;
}

INITIAL FUNCTION

/**
* Display the nodes of a view as plain nodes.
*/
function theme_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
foreach ($nodes as $n) {
$node = node_load($n->nid);
$output .= node_view($node, $teasers, false, $links);
}
return $output;
}

Hope it help,
Erwan

Status:Active» Closed (won't fix)

Sorry, this support request is way too specific. Please have a look at the issue queue - Views maintainers are buried already.