I feel like I've tried every permutation in Views Contextual Filter to achieve this, but after countless hours I've decided to ask for help. I'm sure this issue is too basic to use up too many kbs on the server so briefly:

I want to make a related nodes pane, showing teasers of nodes that have the exact same taxonomy terms as the node being viewed. But not show all nodes that are tagged with the parent items.

Example (imagine I'm selling clothing for your extremities):

►Men
►►gloves
►►hats
►►shoes

►Women
►►gloves
►►hats
►►shoes

So, with the node being viewed tagged with ►Men ►►gloves, I just want to display nodes with ►►gloves, tagged under the parent ►Men. Simple.

I don't want any nodes tagged with:
►Men ►►hats
I don't want any nodes tagged with just:
►Men
I don't want any nodes tagged with:
►Women ►►gloves
I don't want:
duplicates.

Under contextual filters, I've tried combinations of:
→ has taxonomy term id
→ has taxonomy term id with depth
→ has taxonomy term id with depth modifier
→ taxonomy term id
→ taxonomy term name
→ taxonomy term parent

I've tried excluding, including, multiples, from URL, from content, node filters, taxonomy filters...

I guess what I really want to do is omit the parent from the result, but keeps its relationship to its child. I can't seem to achieve this with depth arguments (maybe cause it's a node?).

In the quest for children, I've had so many relationships and arguments I feel I should see a marriage counsellor.

Anyone available?

Comments

dawehner’s picture

I want to make a related nodes pane, showing teasers of nodes that have the exact same taxonomy terms as the node being viewed. But not show all nodes that are tagged with the parent items.

If you try to build the sql doing it you will realized that this task isn't trivial :)

Stupendous Views wont play nicely with my taxonomy contextual filters
Actually there are two keywords,with which you can anger people contribution to views: taxonomy + exposed filter.
Trust me this is really hard. I just tryed it 10min long, and couldn't manage to do it.

If you need some inspiration you could still perhaps use this export


$view = new view;
$view->name = 'strange_taxonomy_issue';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'strange_taxonomy_issue';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'strange_taxonomy_issue';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Relationship: Content: Taxonomy terms on node */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['required'] = 0;
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
  'tags' => 0,
);
/* Relationship: Taxonomy term: Parent term */
$handler->display->display_options['relationships']['parent']['id'] = 'parent';
$handler->display->display_options['relationships']['parent']['table'] = 'taxonomy_term_hierarchy';
$handler->display->display_options['relationships']['parent']['field'] = 'parent';
$handler->display->display_options['relationships']['parent']['relationship'] = 'term_node_tid';
$handler->display->display_options['relationships']['parent']['required'] = 1;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Has taxonomy term ID */
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
$handler->display->display_options['arguments']['tid']['table'] = 'taxonomy_index';
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['tid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['tid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['tid']['add_table'] = 0;
$handler->display->display_options['arguments']['tid']['require_value'] = 0;
$handler->display->display_options['arguments']['tid']['reduce_duplicates'] = 1;
$handler->display->display_options['arguments']['tid']['set_breadcrumb'] = 0;
/* Contextual filter: Taxonomy term: Term ID */
$handler->display->display_options['arguments']['tid_1']['id'] = 'tid_1';
$handler->display->display_options['arguments']['tid_1']['table'] = 'taxonomy_term_data';
$handler->display->display_options['arguments']['tid_1']['field'] = 'tid';
$handler->display->display_options['arguments']['tid_1']['relationship'] = 'parent';
$handler->display->display_options['arguments']['tid_1']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['tid_1']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['tid_1']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['tid_1']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['tid_1']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['tid_1']['break_phrase'] = 0;
$handler->display->display_options['arguments']['tid_1']['not'] = 1;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'article' => 'article',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'strange-taxonomy-issue';
djh007’s picture

Wow - thanks dereine :) It's great to have something to work with... brilliant.

Not trivial? Good, now I don't feel like such an idiot for spending so many hours trying to solve this.

I'm amazed that this function is not required more often? To be able to show other nodes tagged with the exact same term seems so... ordinary.

I think I already tried your View around 3am this morning. I then moved on to try "taxonomy term id" instead of "has taxonomy term id", which seemed to get me closer, but still no success. I've then been trying with 'taxonomy term name', but that got me completely lost.

Maybe I've reached the outer limits of Views' capabilities? The very edge? Is it possible?

dawehner’s picture

With non-trivial i actually mean damn hard :) Sorry that's not possible for you to get out of context.

Additonal note ARRRG TAXONOMY

djh007’s picture

Title: Stupendous Views wont play nicely with my taxonomy contextual filters » Views wont play nicely with my taxonomy contextual filters

I have amended the title to reflect my great frustration.

Do you really think it's impossible with the regular contextual filters to show nodes with a specific term, and exclude the parents / duplicates? (I really can't go down the hand coded Php route, cause my skills are not up to the task).

I wonder how anyone else deals with related node views. Is there no way to use arguments to specify a specific hierarchical depth with terms that come from a node?

How does anyone else deal with this task?

To summarise:
→ Create a view that shows node teasers tagged with the same term as the node being viewed (►vocab ►parent ►term
→ Exclude duplicate parent terms (avoid showing (a) ► vocab ► parent AND (b) ►vocab ► parent ► term, thus duplicating the same node. Just show either (a) or (b) - if (a) is of course tagged with the right term.
→ Only show ►vocab ►parent ►term if the related node has the same parent. (so not ►vocab ► thatsnotmymum ► term

(I'm considering opening a hat, gloves and shoe shop. Might be easier)

djh007’s picture

OK, I figured out half a solution, but I'm not sure if Views can provide the right filters to bring the other half to fruition.

If I add to each ►vocab ►parent ►term a description, which comprises [parent][term], then each term description becomes unique, eg tax description= 'mens shoes' or 'womens hats'. That way I can somehow filter out the parent whilst retaining the term's relationship to the parent, since it's hard-coded into the description.

But is there a way for Views to filter according to taxonomy description? Or is this a ridiculous idea. I'm starting to get delirious.

Is there a way that contextual filters can grab arguments from content loaded in the node page, using 'provide default value: php code'?

djh007’s picture

A compromised work-around. Better solutions are very very welcome!

I have set contextual filters to '(term)taxonomy term:id' and 'has taxonomy term'. This gives good results with my limited tests:

If Node being viewed is tagged ►Men ►shoes, it will only show up nodes tagged with ► Men ► shoes. Not nodes with ►women ►shoes, no duplicates, no nodes tagged with ►men ►hats.

The problem comes when a viewed node has multiple taxonomies applied to it:

►Men
►►shoes
►Women
►►shoes

I get no results. So I've set up a no results behavior to display results 'taxonomy term:id'.

Since most of my nodes are only tagged only with one parent and one term the no results will rarely show, but at least the men can look at some 'shoes', even if they are high heels.

kars-t’s picture

Status: Active » Fixed

Hi

I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.

Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.