By Mansi

2011-08-18 22:18:29 8 Comments

I am new to drupal and currently I am exploring the Views module. I have a dummy website for a toy shop to learn on. I have created taxonomy as follows where "Category," "Ages," and "Brand" are vocabularies, and the rest are taxonomy terms :

  • Category: Activity Centers, Electronics, …
  • Ages: 0-2, 2-4, …
  • Brand: FisherPrice, V-Tech, …

I want to create a view that displays all toys, depending on what has been passed in the contextual filters; for example, if the first argument is a term from the "Brand" vocabulary, the second argument is a "V-Tech" term, then toys belonging to these should get displayed with a URL such as

I selected "Content: Has taxonomy term ID" in the contextual filter, but I don't understand the next screen. I selected the 'Specify validation criteria' checkbox. There should not be a vocabulary option in the validator drop-down? Can anyone help me from here on?


@kiamlaluno 2011-08-18 23:15:58

I cloned the existing default view for taxonomy/term/%, removed all the contextual filter already existing, and then:

  • I added a new relationship, "Content: Taxonomy terms on node."
  • I added a new context filter, "Taxonomy vocabulary: Machine name," for which I didn't change any setting. (The Views module already selected the relationship I defined before.)
  • I added a new context filter, "Taxonomy term: Term ID."

For the "Taxonomy term: Term ID" filter I used the following settings.


I changed the path for the view to "test-term/%" and removed the feed.

The setting page for the view, once done the changes I described, appears as in the following screenshot; I highlighted the parts that are different from the setting page for the view I cloned.


What I obtained is a view that shows the nodes containing the terms from the vocabulary for which I pass the machine name as first argument.

For http://tero.local/dr71/test-term/tags ("tags" is the machine name for a vocabulary I defined in my test site), I get the following result.


For http://tero.local/dr71/test-term/tags/tags (the second "tags" string is the name of a taxonomy term that the "tags" vocabulary has), I get the following.


I didn't find any way to filter out the duplicates that appear in the first case, though. This is would happen only for those vocabulary that allows the users to select more than one term per node.

The relationship with the taxonomy terms is necessary as the view is about nodes; without the relationship, it would not be possible to use "Taxonomy vocabulary: Machine name," and "Taxonomy term: Term ID" as contextual filters. You can check it: If you remove that relationship, you will not able to add them as contextual filters.

@Mansi 2011-08-19 20:34:19

Thank you for ur comment. I selected the vocabularies Brand,Category and Ages and then in Filter value type I chose Term name converted to ID. But now this is working only for one argument which is the term. So when I enter the url as my-url/V-Tech, I see all toys under this term. But how do I specify the vocabulary too as the filter?

@kiamlaluno 2011-08-19 21:42:18

Do you mean to use the vocabulary name as value for a context filter?

@kiamlaluno 2011-08-19 22:51:15

I have updated my answer; I first mis-read your question, and I didn't see you were trying to get a view that would get a vocabulary name and a taxonomy term name as arguments.

@Mansi 2011-08-19 23:45:43

sorry but I am not following your example. :( Basically what I am trying to accomplish is show users a page to browse toys. This page takes in 2 arguments - vocabulary name and term (term will belong to the passed vocab). So something like myurl/Category/Electronics. Is it possible to do this? or should I be using Relationships. (I dont know how to use that either but there was one post explaining Relationships in Views which I read today). or maybe you can direct me to the correct way of doing this.

@kiamlaluno 2011-08-19 23:49:37

It's what I am showing in my answer; instead of starting with a new view, I cloned the existing one for "taxonomy/term/%" and changed it to make it work. Starting a view from scratch would require to set it correctly, which is what is already done if you start with a similar existing view; what is required is to modify the existing context filters, which are removed in this case.

@Mansi 2011-08-20 00:26:39

I understand that you are using an existing default view to explain it to me. I am not clear with the Relationship portion. Here, should I select all of the vocabularies I require from the checkboxes given? Will this create a parent-like relationship for 'terms' ?

Related Questions

Sponsored Content

1 Answered Questions

How use views exposed filters with taxonomy and panels

1 Answered Questions

Use Url Argument in contextual filter for Block View

  • 2017-07-09 13:37:18
  • Abdul Rafi
  • 546 View
  • 1 Score
  • 1 Answer
  • Tags:   views

1 Answered Questions

[SOLVED] Taxonomy term view with number of items for parent and child terms

1 Answered Questions

[SOLVED] Views Contextual filter for matching taxonomy names

1 Answered Questions

[SOLVED] Displaying taxonomy terms and its contents with views

1 Answered Questions

1 Answered Questions

[SOLVED] Override taxonomy term display page with panel page

1 Answered Questions

Sponsored Content