30

I have a vocabulary attached to a content type. Only one term can be selected to categorize a node made with this content type. The vocabulary is called Vehicles and has terms 'cars, trucks, boats.' The content type is also named Vehicles.

I use path auto so that it shows [vocabulary:name]/[term:name] so when rendered it will show site.com/vehicles/trucks, for example, which will show all the trucks... typical Drupal stuff.. Ok...

Now, I have a View that is a page with a path 'vehicles.' It is setup to to display all of the items of content type 'vehicles.' This page view is also setup to take an argument 'taxonomy term id.'

Note that when the taxonomy term is present, the url alias generated for the taxonomy path is the exact same as as the Views page with an argument supplied:

URL Aliased taxonomy path = vehicles/trucks. Views page with argument = vehicles/trucks.

This is on purpose. My goal was to show all results of that content type when an argument was not present, and when it was present, it would most importantly filter the results based on that taxonomy term AND keep the same fields and structure as without the argument (same as site.com/vehicles).

The problem is, this is not working as expected. site.com/vehicles correctly shows my view and related filters. site.com/vehicles/trucks shows just the regular, unformated taxonomy list supplied by Drupal.

Is this because Taxonomy term ID argument is not configured correctly?

Is this a weight issue where taxonomy hooks are firing after Views? If so, how can I rearrange the weights here so that it fires correctly and gives me the results I need?

I know what you are going to suggest - that Views comes with taxonomy/term/% view to override drupal default views.

However, this is not going to work in my case. I have multiple content types each with its own vocabulary and each with its on view and distinct set of fields (houses and cars, for example have very different field sets). The taxonomy/term/% would work if all content types had the same fields, then I could just mimic those in that override, but since that is not the case, how can I correctly get my path with argument to show the results based on that vocabulary term and keep my field structure?

Sorry if that was confusing. A link to the site for reference http://www.buyagainbaby.com. The site does currently use taxonomy/term/% as an override, but again, that has to change so that each view is responsible for how it renders its result set based on taxonomy.

5 Answers 5

20

All of these answers are great solutions, and thanks for taking the time to provide such infomative answers. Ashlar, your response taught me a lot about how taxonomy works works as well as the relationship between views and taxonomy.

I found a solution that works great for my situation, and I will share that in case it may help you guys too.

As I explained above, the my problem was that my view, with no argument, supplied the results I wanted, but the default taxonomy view with an argument, which was not what I wanted.

To solve this, I installed the module Taxonomy Display http://drupal.org/project/taxonomy_display. I then reconfigured each view to have Taxonomy Term ID as an argument.

Taxonomy display lets you associate a vocabulary with a particular view. Now, when I click on vehicles/trucks, which is an alias for taxonomy/term/3, the view takes over and this is actually rendered correctly maintaining the integrity of the field structure.

If anyone wants to know more details about the configuration please let me know.

2
  • Your solution sounds like a great plan! Unfortunately, I don't get the "Taxonomy display lets you associate a vocabulary with a particular view"-part... Could you explain it to me a bit more in detail?
    – Michiel
    Commented Jan 10, 2013 at 16:22
  • Once the taxonomy display module is installed you will see in its settings options to control how taxonomy term lists are displayed. Views is an option. You choose the view, and then choose which item in that view you want your taxonomy list items to look like. This all assumes that you have already created a view that lists content just like you want. Once you hit save, your taxonomy list looks exactly like the output of the view you selected in the settings.
    – blue928
    Commented Jan 11, 2013 at 6:59
7

I believe there are several factors to consider in your setup:

  • Every path must be unique to access a page, a term, a view, or a page panel If you have two pieces of content with the same address, you lose control of the display. Drupal gives taxonomy term precedence over Views so it will not be called. The View definition using taxonomy/term/# will intercept the taxonomy term, but as you indicated, does not display a meaningful URL.

  • Views do not respond to aliases. That is because the first thing Drupal does with any request is to convert the alias to a node/nid format standard for all Drupal content. So in your case vehicles/trucks is converted to the node/# assigned to the view. View cannot take context from an alias directly.

To get what you want you do one of several things.

  • Create a menu with the callbacks set to the path of your view. This will generate the correct URL and allow the View to respond.

  • Use Panels with Page Manager (in Ctools Suite) enabled. If you define a Page Panel defined for the appropriate URL you can place your View in the panel pane or pass the context from the panel page directly to a Views content pane. A content pane does not have a path. Instead it takes the contexts such as the path, set by the page panel directly, to create its content. This video series at nodeone.se does an excellent job of demonstrating how to use panels and page manager effectively.

  • Another way to get views content to the screen is to use quicktabs module. I don't think it fits your specific situation, but it also can directly tap into views by selecting the tabs you define for a page.

4

Views has a built-in view that emulates and overrides taxonomy terms. Simply enable it to override taxonomy listings with views. Taxonomy view

2

I actually did a similar thing a few days ago. My solution isn't elegant but it works. What I did was to override the Taxonomy term display using Panels, not Views. I then added all of my different views for each term to the Panels content area. Since in my case each view has a filter that limits it to results of a particular vocabulary, when you visit the taxonomy term page, it shows only the view for that particular vocabulary.

Let me know if you need more information about how I implemented this.

3
  • Im not a big panels fan, but that is a possible route. Also, I followed this tutorial here leveltendesign.com/blog/dustin-currie/…. This works perfectly, except that it uses the taxonomy id number but I need the taxonomy name as with hyphens instead of spaces. Ever done any trickery like this?
    – blue928
    Commented Apr 6, 2012 at 1:05
  • 2
    We do this all the time. Panels defines a page for this (though disabled by default) out of the box, so I would hardly call this inelegant.
    – mpdonadio
    Commented Apr 6, 2012 at 1:30
  • I would like more details! :) Commented Sep 14, 2017 at 20:11
1

A great solution has been proposed by WebbyKat, to set your page path to /taxonomy/term/% instead of /categories/%

It works, but it will rewrite all of your terms into one View.

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