Community Documentation

Override taxonomy pages with Views 2

Last updated October 1, 2012. Created by lelizondo on April 5, 2009.
Edited by batigolix, ultimateniks, cedewey, cheekdotcom. Log in to edit this page.

Note: I have requested that this be added to Advanced Help within Views -- see http://drupal.org/node/495658

Views 2 provides an excellent way to override the taxonomy pages of any term. The view is included by default but is disabled. This page covers three minor aspects that some users could use to control the aspect of their taxonomy pages, it won't cover how to theme the view because this topic it's covered in some other pages of this book.

Background

The Taxonomy module provides a way to organize content through the site. It also presents a page with nodes that belong to some term. The style can't be changed easily and taxonomy only displays node teasers.

Force All

When using vocabularies with multiple term levels, a top level won't include the nodes that belongs to the levels inside. Let's clarify this with an example, let's assume the site have this vocabulary:

Vocab
- Term 1
   -- Term 2
   -- Term 3
- Term 4
   -- Term 5
   -- Term 6

If you go to taxonomy/term/1, then you see all nodes in Term 1 listed, but not nodes in Term 2 and Term 3. If you want to see all nodes in Term 1, Term 2 and Term 3 in a single page, you have to go to

taxonomy/term/1/all

With Drupal 5.x a user could 'Force' taxonomy to show 'all' terms inside another term with the Taxonomy Force All module. Unfortunately the module won't be upgraded to Drupal 6.x. Fortunately this can be done with Views 2.

Step 1. Enabling taxonomy_term

The first step we need to do is to enable the "taxonomy term" view that views provides for us. After we've done that we need to edit it.

Step 2. Changing minor aspects

On the Display: Page, we can change the Style to any of the styles that views provides for us, it could be a table or a list. If we do this it's necessary to add some fields to the view.

The most important thing we're going to change is the argument Taxonomy: Term ID: (with depth). At the bottom of the screen, you'll have 2 options, the first one to change it's the depth, if we want to do what the Taxonomy Force All modules does, you'll have to set it up for at least 1.

The next thing you have to do it's check the Set the breadcrumb for the term parents option. This will allow your view to show the breadcrumb with all the term levels in your taxonomy.

Save the changes and try. Next you could do whatever you want, like adding fields, theming, exposing filters, sorting or adding feeds.

Theme every vocabulary/term independently

Thanks to TVI: Taxonomy Views Integrator now it's possible to theme every vocabulary or term with it's own view. All you have to do is clone the view in Step 1 and set it as the TVI active view in the vocab or term edit pages.

You can read more about this module at the module page.

Comments

What is the best way to override only two, three or even one taxonomy term using Views 2 and built-in "taxonomy_term" view?

What I have to do if I want to override only terms, that have children terms or just want to override only certain term/-s?

I looked through the documentation and searched forum, but was unable to find an answer.

• •
¤ Data Recovery | ¤ Halo 3 | ¤ Melodiya Records

The answer is right here, you

The answer is right here, you have to use the module TVI (Taxonomy Views Integrator). With that module you can create a different view for every term or vocabulary if that's what you want

Luis

That doesn't help for terms with multiple parents

I have a hierarchical vocabulary. Some terms have multiple parents.
I want to base my view on the URL and have it override the taxonomy view, but it seems to be failing... basically I want every term beginning at a certain term with all its children, to have the same view. But some of those children are children of other parents. They'd have a different view if brought up under the parent's URL.

Subscribing... Great info.

Subscribing... Great info.

Hi, another way to achieve this in Drupal 7, without the TVI module or the display module, but with the Viewfield module, which add a field of type "view" to a content (it works already with the developpement version of Viewsfield):

1. install and enable the Viewsfield module (http://drupal.org/project/viewfield);
2. create the different views you want to display for the different taxonomies or taxonomy terms, with as contextual filter, the term ID (with or without depth, as you want) (option "provide default from the url");
3. create a field of type "views" in the differents taxonomies (admin/structure/taxonomy/[taxonomyname]/fields) of wich you want to modify the display, let's name the field "displayed_view", and choose for each taxonomy (or term) the view you want to display in this field;
4. create a view of type "taxonomy terms" (not content, that is to say: do not duplicate the provided "taxonomy term" view) and add as path "taxonomy/term/%" (to override de default core display). Let's name it "term_display". Add as field the field "displayed_view" you just created and as contextual filter the term ID (option "provide default from the url");

Now, that's it: the view which "overrides" the default term display is the same for all the taxonomies, but the displayed view is different, following the value you choose for the field for different taxonomies or even different terms!

A bonus: if you want to modify the title of the view, for example to display the name of the term as page title, you can add a second contextual filter to the view "term_display" : the term's name. Then choose "provide default value" > php code and add the following code:

if (arg(1) == 'term' && is_numeric(arg(2))) {
$term = taxonomy_term_load(arg(2));
$name = $term->name;
return $name;
}

Then choose "override title" and add "%2" as argument. That's it!

Hope this will help somebody, I was happy to find this solution for my project.

Viewfield for different taxonomies override

audealexandre, thanks for the detailed steps on how to display custom taxonomy term pages with the Viewfield module which I found very helpful. Using your method I managed to get the taxonomy term pages display with their page headings as intended except I can't get a custom taxonomy page title (not heading) using the Page Title module. The page title keeps defaulting to the term name. I wonder if you have Viewfield working with a custom page title.

Create node forms became very slow 15 sec to load

I have override my taxonomy page,
now all my create content forms are taking 15 seconds to load.
I rolled back this.
Any reason, solution?

--
Ashish

audealexandre, THANKS SO

audealexandre, THANKS SO MUCH. After nearly 8 hours of trying everything, your suggestion worked. I want to individually control hundreds of taxonomy pages going to only 7 or 8 views, and every module I tried did not work. TVI was the closest, but the arguments were not being passed. Still really buggy. this worked in the 5 mn's i took to try it.

I can sleep tonight without my brain overloading!!!

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Designers/themers
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here