Views and Taxonomy

frankdesign's picture

Hi all

I'm building a commerce site on D7 at the mo and I have a views & taxonomy question. I have a created a hierarchy taxonomy to tag the products and I'm using the view 'Taxonomy term' that comes default with Views to display the products. So far so good. But I need to group the products by taxonomy terms. Now for the spanner in the works! Most nodes have several Child Taxonomies from different Parents assigned to them. So I tried adding the Taxonomy field to the view, excluding it from display, and using it to group the view. But I don't see a way to filter this field so it only groups by the Child Taxonomy related to the Parent its grouping under. For example, I'm trying to achieve something like

Fruit (parent)
-Apples (child)
--Golden Delicious (node1)
--Pink Lady (node2)
Colour (parent)
-Red (child)
--Pink Lady (node2)
-Green (child)
--Golden Delicious (node1)

By grouping by taxonomy terms I end up with something like

Fruit (parent)
-Apples, Red
--Pink Lady (node2)
-Apples, Green
--Golden Delicious (node1)
Colour (parent)
-Apples, Red
--Pink Lady (node2)
-Apples, Green
--Golden Delicious (node1)

I've tried changing the settings on the Taxonomy field under Multiple field settings but to no avail:
• unchecking 'Display all values in the same row - gives me multiple results
• changing 'Display All Values' to 'Display 1 value' solves the problem under 'Fruit' but I loose the colour taxonomies under 'Colour'.

I also tried approaching this from another perspective. I created a Taxonomy View of the Taxonomy Terms and a Node View of the Products with a term id contextual filter. I then added the Node View as a field to the Taxonomy View using the module Views Field View. While this technically worked, it does add a bit of overhead to the view. It also creates a problem with the length of the views result as the pager only counts the results in the Taxonomy view - so while I can set that view to display only 5 results, each taxonomy term could have 20 products - so I could end up with 100 results!

Can anyone point me in the right direction? I've Googled the living daylights out of this one and I can't seem to find the right answer. I have a sneaking suspicion that the two views set-up is the right way to go, but the way I have done it is not the best solution.

Sorry for the long email

Thanks a mil

F

Comments

Hi Frank, I have done

kaipee_s2s's picture

Hi Frank, I have done something similar except it was for an estate agency website.

I had to create country > county > area > city

The best way I could figure out to do this was to create each as an individual vocabulary for the 'category' and only one layer of terms for the 'items'. So that for every 'fruit' term you create (apples, oranges, etc.) under the vocab 'Fruit' - you also create a separate vocab for that term, with its own set of terms describing the type.

Then I just created an autocomplete widget (to allow easy select and addition) field for each vocabulary as a term reference on my node.

Then used a View with each of those term reference fields along with an exposed filter for each field.

For your needs, you could probably just create a filter (select field) for each vocabulary to allow filtering your node by any nodes that have just that term associated to it.

Example:

Vocabularies and terms

voc: Fruit
-- term: Apples
-- term: Oranges
-- term: Bananas

voc: Apples type
-- term: Golden Delicious
-- term: Pink Lady

voc: Oranges type
-- term: Tangerine
-- term: Clementine

voc: Color
-- term: Red
-- term: Orange
-- term: Yellow

Node Fields (term references)

field_fruit
field_apples_type
field_banana_type
field_oranges type
field_color
(you could then use dependencies to show/hide each field depending upon a 'parent' field)

View

field_fruit
field_apples_type
field_banana_type
field_oranges type
field_color

exposed-filter-(field_fruit)
exposed-filter-(field_apples_type)
exposed-filter-(field_banana_type)
exposed-filter-(field_oranges type)

This should allow you finer control, especially when used with dependant fields, although a little extra work. It will also allow you to do things like only show the color selection when 'apples' have been chosen (because who wants a tasty red banana, right?)

Ireland

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week