5

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 http://example.com/Brand/V-Tech.

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?

7

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.

screenshot

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.

screenshot

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.

screenshot

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.

screenshot

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.

  • 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? – Mansi Aug 19 '11 at 20:34
  • Do you mean to use the vocabulary name as value for a context filter? – kiamlaluno Aug 19 '11 at 21:42
  • 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. – kiamlaluno Aug 19 '11 at 22:51
  • 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. – Mansi Aug 19 '11 at 23:45
  • 1
    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. – kiamlaluno Aug 19 '11 at 23:49

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.