Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By soezkan on
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
In your list of fields for
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.
select the Term field ... and
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
Add the relationship to the
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.
Thanks
Just wanted to say thanks MB...You saved me a few hours. Also, thanks to the original posters to posting the question.
Drupal 9.4
Still working in Drupal 9.4.8. Thanks a lot!
Does this work if the node
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
Duplicates...
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,
));
Help...
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
solution tested on drupal 7
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...
Thanks a lot intyms this
Thanks a lot intyms this worked for me
This solution still works in
This solution still works in D8. Thanks!
Yeah it still works for
Yeah it still works for Drupal 8.9.7. Thanks!
- Nigerian web designers
Worked in Drupal 8 also
Thanks it works in drupal8 as well.
Thanks @intyms this solution
Thanks @intyms this solution working on D9
This worked out of box for me
Hi,
Below post helped me. I'm sure this may help you too....
http://drupal.org/node/434734#comment-3843240
In Drupal 9.4 using Entity Reference List
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".
Thank you so much
Thank you so much @pierregermain