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.
How can I set the filter block to show a hierarchical taxonomy? As far as I can see there is only a flat list being built by default. How can I change this and apply the hierarchy of a taxonomy?
Comments
Comment #1
Chris Gillis CreditAttribution: Chris Gillis commentedThis is really beyond the scope of this module, but you could try something along the lines of:
Comment #2
ssoulless CreditAttribution: ssoulless commentedWell that is a good solution but should be good more suggestions, I think this should be implemented due to usually the isotope filters are that "FILTERS", so this is now a feature request, add way of create filters with hierarchy...
Comment #3
Chris Gillis CreditAttribution: Chris Gillis commentedComment #4
ssoulless CreditAttribution: ssoulless commentedLook what I meant is have something like this
taxonomy vocabulary= "car brands"
-renault
--clio
--twingo
-bmw
--z4
so if for example I have an isotope view of "cars" I want to filter them by its brand so the initial filter block should be something like
renault | bmw
then if I select "renault" the view should show all the items that match that category, and then the filter block should show its sub categories
renault | bmw
clio | twingo
then you can choose one of the subcategories if you want to filter more. that's it...
the module https://www.drupal.org/project/views_tree works with the view items not with the filter block of isotope
Comment #5
ssoulless CreditAttribution: ssoulless commentedRight now the filter block just show a flat list of the terms without consider the hierarchy of the terms so the filter block just looks like this
renault | clio | twingo | bmw | z4
and for example you have a car item that is "clio" so if you select "renault" in the filter block it should show that item but id does not, it only is showed if you select "clio" in the filter block
Comment #6
Chris Gillis CreditAttribution: Chris Gillis commentedI understand. Thank you for your feature request. I'll take it into consideration as we develop 2.x
Comment #7
mccrodp CreditAttribution: mccrodp at Open source, open mind commentedI think what @ssoulless was looking for originally here is integration with hierarchical_select module.
Comment #8
Chris Gillis CreditAttribution: Chris Gillis commentedMoving feature request to new module.
Comment #9
robcarrWhat I've noticed when trying to implement a filter on taxonomy term parents is that the parent appears to be using the hierarchy of the Isotope filter. So using the car analogy, the 'parent' of clio, twingo and z4 is only the Isotope 'All' option, rather than a list containing renault and bmw.
And in my example, I've built a relationship on a taxonomy term in the Views > Block (Isotope filter), using:
And then render only one field in the block: (Parent) Taxonomy term: Name. This field is also main Isotope view page (so it can be added as an Isotope data field but excluded from view). All I get is the 'All' item listed on the 'Manufacturer' filter block, even with no aggregation. When used in anger, clicking on the Manufacturer 'All' filter actually resets the Car filter to all items.
Comment #10
voughndutch CreditAttribution: voughndutch commentedIs this functionality available yet, if so can you give any pointers on how to achieve this. I have been trying to do this for the longest but I have had zero luck.
Comment #11
voughndutch CreditAttribution: voughndutch commentedI have a Vocabulary Tags setup like such:
Parent A
Parent B
Term 1
Term 2
Term 3
Term 4
Term 5
Term 6
All terms(Parent A and B included) share the common Parent (root) so its obvious some terms have multiple parents.
What I need is my filters to appear like [ALL] [Parent A] [Parent B] where selecting all would show all content no matter the term and selecting a parent would filter content containing Parent term or children.
Comment #12
dimmech CreditAttribution: dimmech commentedThe way that this module currently outputs html from taxonomy vocabularies for filtering, does so assuming that the user would apply filters that are independent of each other. This makes sense because it's normally how filters work. Multiple filters are used so that you can narrow the results of a large data set based on filter combinations. However, for simpler uses, some of those combinations can also be structured in the form of nested terms in a vocabulary. An example of this would be a basic store menu which doesn't necessarily give reason to use multiple filters, but can benefit from a single nested structure. You could use this to implement a themed menu and take advantage of the cool things that this module can do. If you want an Isotope filter block with hierarchy for your store menu here is one way to accomplish this.
First, create your taxonomy vocabulary and nest the items into a menu structure. Remember that the weight values in this step will set the order of items in the hierarchy. If your resulting structure is not right, revisit this step and check the weight values.
Next, the filter block needs to know some basic information about how the taxonomy is nested. For this I chose to use a combination of Taxonomy Lineage and Views Conditional as a starting point. You can use this combo in views to query each taxonomy term for its "depth" then "rewrite the output" based on the result to add custom classes.
Here is the view I used, import it after installing the required modules. The vocabulary I used in this view is named "Product Class (Hierarchy)". If you use another name for your vocabulary be sure to change it in the imported view under "Filter Criteria".
View to import
Now, add a preprocess function to your theme's template.php file. This will load the js and css files we will need to make this all work when the view named 'store' is called. Substitute my_theme with your theme's name where applicable. Also, be sure that the file paths match your structure and that the view name matches your view name.
Then you need to create some js to rewrite the output further with the following objectives.
1. Replace the "All" filter label with text of our own choosing.
2. Target the top level list items for adding classes since there is no parent selector in css. I did this by using the newly created custom classes from our view as selectors to assign classes at their top level <li> elements.
3. Add some hover classes to enable some interaction with the list items through css.
Create a js file at the path specified in the pre-process function we created. In this case the path can be found in a sub-folder of my_theme at /custom/store_menu/store_menu.js
js code
Finally, add the css file to the same location as specified in our preprocess function.
css code
The css and js included here are meant to be used as a place to start and not a finished solution. At this point you should have a hierarchical menu that is customisable to suit your needs!
Note: This does not create a nested html structure although that too can be achieved using js. This is simply the way I chose to do it which is just a different path to the same destination.
Comment #13
voughndutch CreditAttribution: voughndutch commentedi really appreciate your time explaining this. im going to grind through this thank you