Hi there,

I build a view to show a certain vocabulary. This vocabulary
contains terms with sub-terms. But I want to show only the
parent-terms without the sub-terms. How can I do that?

I have in the views settings in the second column:
Relationships
Taxonomy: term

... and in the third column:
Filters
Taxonomy: Vocabulary = My Vocabulary

How can I manage that?

Thanks so much for help!!!

My best,
Soezkan

Comments

matt_harrold’s picture

In your list of fields for the View ... select the Term field ... and set its' relationship to be Parent Term. Also set the view to be "Distinct".

Then in your arguments, add one for Term ID and you should be good to go.

soezkan’s picture

select the Term field ... and set its' relationship to be Parent Term.

But where can I set its realtionship to be parent item?
There is no option to do so or at least I can't find it.
What I see, wenn I select the Term field, by clicking
on it, is:

Exclude from display

Rewrite the output of this field

Output this field as a link

Trim this field to a maximum length

Link this field to its taxonomy term page

Can you please give me another hint how to solve this?
Thanks alot!

Soezkan

MBroberg’s picture

Add the relationship to the view first. Then the relationship option will show up in the taxonomy field. Select the parent as the relationship and the parent term will be displayed instead.

mikejonesok’s picture

Just wanted to say thanks MB...You saved me a few hours. Also, thanks to the original posters to posting the question.

pierregermain’s picture

Still working in Drupal 9.4.8. Thanks a lot!

pratip.ghosh’s picture

Does this work if the node have multiple parent categories, because when there are multiple, it is showing the same row with each parent?

Row 1 = NODE1 Parent1
Row 2 = NODE1 Parent2
Row 3 = NODE2 Parent1
Row 4 = NODE2 Parent2
Row 5 = NODE2 Parent3
Row 6 = NODE3 Parent1

Specifically I would like something like :

Row 1 = NODE1 Parent1, Parent2
Row 2 = NODE2 Parent1, Parent2, Parent3
Row 3 = NODE3 Parent1

Is this possible? Hope I make myself clear...

-- Pratip Ghosh

stinky’s picture

I'm trying to do the same thing, but even though I've set Distinct to "yes," I'm getting duplicates.
Any ideas on how to get rid of the dupes?

Screenshot is at http://dev.library.uaf.edu/kingsley/dupterms.gif

The Export for the view is here:
$view = new view;
$view->name = 'fpc';
$view->description = 'Front Page Categories';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'parent' => array(
'label' => 'Parent',
'required' => 0,
'id' => 'parent',
'table' => 'term_hierarchy',
'field' => 'parent',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_taxonomy' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'term_data',
'field' => 'name',
'relationship' => 'parent',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('filters', array(
'vid' => array(
'operator' => 'in',
'value' => array(
'1' => '1',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'vid',
'table' => 'term_data',
'field' => 'vid',
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'publish' => 'publish',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 1);
$handler->override_option('row_options', array(
'inline' => array(),
'separator' => '',
'hide_empty' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('style_options', array(
'grouping' => 'name',
));
$handler->override_option('path', 'home');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));

saurabhi’s picture

Hello soezkan,

I want to create a page view to show parent taxonomy terms with their subterms also.

Can you help me? I tried different configurations but couldn't achieve that.

I have already posted this issue here.

http://drupal.org/node/670540

intyms’s picture

in Drupal 7 to only show parent terms you add a "contextual filter" and add "Taxonomy term: Parent term", then set "Provide default value" to a "fixed value" of 0. That will filter out the child terms.

source: drupal.stackexchange...

khurrami’s picture

Thanks a lot intyms this worked for me

capysara’s picture

This solution still works in D8. Thanks!

chike’s picture

Yeah it still works for Drupal 8.9.7. Thanks!

khurrami’s picture

Thanks it works in drupal8 as well.

MahmoudSayed96’s picture

Thanks @intyms this solution working on D9

goldengalaxy’s picture

Hi,

Below post helped me. I'm sure this may help you too....

http://drupal.org/node/434734#comment-3843240

pierregermain’s picture

If you need to Configure a View that uses Format Entity Reference List (Needed when you want to filter out values in dropdown fields) we can't use Contextual Filters because it returns the value of a field, not his parent field. So I was able to show parents using the following configuration:

- Format: Entity Reference list 

- Advanced > Relationships : The parent term of the term : (We do not need to check "Require this relationship")

- Fields:
  - Taxonomy Term: Name : "Do not use a relationship" and "Link to Taxonomy Term"

- Filter Criteria:
 - Taxonomy Term: Term Parents: "Do not use a relationshipt" and "Operator is equal to (We keep it with no value)"

- Relationship: The parent term of the term. We do not check "Require this relationsip".
 

arun. joshua’s picture

Thank you so much @pierregermain