1

I have these following 4 Taxonomies
1. New Taxonomy
2. Content Category
3. Technology Taxonomy

  • Applications
  • Gamification
  • Architecture
  • etc. Totally 170 terms

4. Vertical Taxonomy

  • Automotive
  • Banking

Have used Taxonomy term views to create listing pages for these. I want to know is it possible for me to dynamically combine multiple taxonomies ( Technology & Vertical) to display content. Eg : example.com/applications/automotive . If yes how can this be done?

3

Yes, you can do it with Contextual filters in Views. You can Duplicate the Taxonomy term Views and work on it, disable the original for future reference.

You need to add one Contextual filter for each of your Vocabularies. You probably have one field for each of those on your Content type, so add the Taxonomy reference fields as your Contextual filters. The alternative is to use "Has taxonomy term" twice and limit Vocabularies.

You'll need to set up a default value taken from the URL. You can find a lot of tutorials online about the details of setting it up: Add a contextual filter to a view, How to use Contextual Filter in Drupal 8.

The above approach will only work with term IDs example.com/16/35.

To have term names displayed instead of TIDs you need to add a Relationship to the Taxonomy field to your Views, then add Taxonomy term: Name in your Contextual filters and it will use that Relationship in the Taxonomy Contextual filter. Repeat for the other Vocabulary. Also see this answer: How to setup view to filter based on second URL parameter?

That is how you can get example.com/applications/automotive.

  • When i add more than one Contextual filter and set -> Provide default value to taxonomy term ID from url -> Load default filter from term page or more than one "Has taxonomy term" then there is no content displayed in the page. When i add just one contextual filter or Has taxonomy term only then content is displayed and example.com/3222/3033/ gives page not found whereas example.com/taxonomy/term/3033/3222 works but still no content displayed – RK251 Jan 29 at 5:26
  • 1
    Of course you get Page not found if you haven't set up two Contextual filters but you enter two arguments in the Link. You need to test each Contextual filter individually, does it work when you only add one field, and enter one term ID into the Preview example.com/3222? Then delete that Contextual, add another and test for the other Vocabulary example.com/3033. Once you have them working individually you know they will work together. You can also bypass one Contextual with all: example.com/all/3033 or example.com/3222/all. Did you add %/% to Path? – prkos Jan 29 at 5:33
  • Got this part working by selecting %/% as path. The next step I have added two taxonomy reference fields - relationships field_case_study_industry: Taxonomy term & field_case_study_technology: Taxonomy term and selected require this relaitonship. Added two more contextual filters - Name -> Selected the Relationships. When the Filter value is not in Url -> selected display all and When filter value is in the url -. Selected Taxonomy term name and selected appropriate Taxonomy . Now example.com/taxonomy/term/3033/3222 works but example.com/automative/applications says page not found. – RK251 Jan 29 at 7:02
  • 1
    How many Contextual filters do you have? Did you delete the original two that worked with term ID? If you have Relationships then you only need the two Name Contextuals. Be careful which Relationship you choose for which Contextual (you need to match the correct field/vocabulary). Test them as before, one by one, then when you know both are working independently they will work together too. Be careful about the Case settings too, and if you chose the correct Validation criteria. It will work if you have all the details set up. – prkos Jan 29 at 7:13
  • Yes, delete the ones with term IDs, those are two different solutions. Keep the ones with Name. – prkos Jan 29 at 7:20
0

Thanks to prkos solved this problem. Will put down the steps I did to accomplish this.

  1. Disabled the taxonomy term view
  2. Duplicated the taxonomy term view added two contextual filters using my two taxonomy reference fields - field_case_study_industry, field_case_study_technology. Now I set the options of WHEN THE FILTER VALUE IS NOT IN THE URL to provide default value and selected Taxonomy term ID from URL . Check the Load default filter from term page. Now I set the path to /case-study/%/%. This works perfectly for example.com/case-study/3033/3222
  3. To add the term name in the url. Added two relationships: Taxonomy term referenced from field_name. Unchecked require this relationship. Added two contextual filters "Name". Selected the Relationship. And for When the filter value is not in the URL, chose display all results. So now the url /case-study/applications/automotive works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.