By chefnelone


2012-02-02 20:03:10 8 Comments

I have create a view to show the terms of the Products vocabulary.

I the view I set:

Format: Html list

Show: field

Fields: Taxonomy term: Name

It works fine but it the hierarchical structure is lost.

The Products vocabulary has this structure:

-Cars

--Ford

--Volvo

-Computers

--Desktop

--Laptop

But in the Views the terms lost the hierarchical structure and are listed like:

-Cars

-Ford

-Volvo

-Computers

-Desktop

-Laptop

What am I missing here??

6 comments

@Mahmoud Mostafa 2013-04-21 01:45:39

Views Tree is nice for fast and simple hierarchy configuration but it lacks some features like different fields/configuration for different tree levels and grouping

You can get more flexible configuration with Views Field View.

This is the setup I needed for a taxonomy tree of three levels where I needed grouping by top level term.

  1. Create a view of terms with a page display(or any other display)
  2. Add relationship "Taxonomy term: Parent term"
  3. Add Field : Term name(without relationship), Term Name(Parent relationship, excluded from display)
  4. Add Filter Taxonomy term: Parent term (Parent relationship) equal to 0. (show only level 2)
  5. In Format settings, use grouping with field (Parent) Term Name.(to display level 1)
  6. Add A new display (an attachment is good)
  7. Override its fields (just click any field, choose this attachment(overridden) from the select box on top, and then save the field. (this is to avoid recursion)
  8. Override the attachment Contextual filters by adding Taxonomy term: Name (Parent relationship)
  9. Add a view field (Global: View) to your view fields.
  10. Use the attachment in the view field config, and add the token for the term name (not the parent) as the contextual filter value sent to the attachment.

You can remove the relationship from the filter in step 4, this will display the top level in main display, so you can skip grouping (step 5), then add a new display for each level you want to display (control no. of levels to display)

For me this gave almost the same results of Views Tree but with the flexibility I needed.

@Artur 2012-02-02 20:43:22

I would recommend that you give a try to Views Tree module which installs a tree-style (adjacency) Views style plugin which allows you to list vocabulary in a hierarchical way.

Comment: Views Preview does not show the tree layout but normal page display does output as a tree.

@Andrey Rudenko 2014-02-02 10:35:19

@Pol Dellaiera 2014-06-16 09:35:08

You may use the module Views Term Hierarchy Weight Field. It provides a new sort filter to sort terms by their hierarchical order.

@Peter Lozovitskiy 2012-07-23 09:18:43

I've solved similar task by using the Taxonomy menu module.

Transform any of your taxonomy vocabularies into existing menus easily!

Features:

  • Custom Menu per vocabulary
  • Uses the Terms default Path
  • Integrate with Views
  • Integrate with Path Auto
  • Customize the menu path to anything using hooks: Developer Documentation for version 6.x-2.x
  • It doesn't interfere with other menu modules

@deem 2013-12-21 18:30:38

I recommend to not use this module if you want to build i18n site. It makes big problem in this case.

@Peter Lozovitskiy 2013-12-22 01:31:05

Can you describe in particular which type of problems this module has for i18n site? I had no problem with internationalization with this module.

@deem 2013-12-22 09:10:12

If you have i18n taxonomy and i18n menu there is no way to run it properly. You can read about it on the module project site even. There is no support for that.

@robydago 2012-02-02 21:50:17

Views Hacks has a views_summary_taxonomy submodule that seems to do what you are looking for:

"It displays a hierarchical summary of the taxonomy terms in your view results."

http://drupal.org/project/views_hacks#views_summary_taxonomy

@mariomc 2012-02-02 20:28:49

If you only have 2 level category tree and don't mind losing the ul nested format or hacking away with theme files, you can obtain such a functionality by following:

  1. Adding a "Parent Term" relationship to the View and require it.
  2. Having two "Term Name" fields. One without a relationship, and another hidden from display field using the newly created relationship.
  3. Use the hidden field as a grouping field.

Not sure if it was exactly that which was intended...

@chefnelone 2012-02-02 22:52:59

it is a good try but not exactly what I need.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Facets hierarchical taxonomy terms not working

1 Answered Questions

[SOLVED] How do I create hierarchical taxonomy terms on import nodes?

1 Answered Questions

1 Answered Questions

[SOLVED] Displaying taxonomy terms and its contents with views

2 Answered Questions

[SOLVED] How to display only parent terms of hierarchical terms in Views field

1 Answered Questions

[SOLVED] How to get Taxonomy Menu working properly with Contextual Filters in Views?

1 Answered Questions

2 Answered Questions

[SOLVED] Pages by taxonomy in Drupal 7

Sponsored Content