2

I currently use only one view with path taxonomy/term/% and without any vocabulary verification.

However, I would like to create two views: news and products (to implement different themes) linked to two vocabularies (1 per 1): news_categories and product_categories.

news_categories looks like:

  • category 1
  • category 2

product_categories

  • category 1

    • subcategory 1
  • category 2

  • category 3

    • subcategory 1

I don't want to allow displaying terms which are not from this vocabularies. In addition I use pathauto to generating path, which sometimes are a few level dept.

I found a module called Taxonomy Views Integrator, but I'm not sure it's in 100% stable, so my question is that you are any other ways to handle many taxonomy term pages by views?

5

Required modules: Views, Pathauto, Simple hierarchical select, Taxonomy Views Integrator.

Create content type "food".

Create vocabulary "food" add some example terms:

+ fruits
  - apples
  - orranges

+ vegetables
  - carrots
  - potatoes

Pathauto settings

go to: admin/config/search/path/patterns and set the taxonomy term paths:

pattern for all food paths -> [term:vocabulary]/[term:parents:join-path]/[term:name]

Thanks to this pattern our food paths will look like: food/fruits/apples and may contain more than one parent, for example: food/parent1/parent2/parent3/child

Go to: admin/structure/taxonomy/food and check if all paths are setted up correctly. If not, edit them and check Generate automatic URL alias.

Views

Create view showing taxonomy terms from food vocabulary and add these three displays:

Page: Title: "`All food content`"

Path: /food

Relatonship: Taxonomy term: Content using Food terms.

Page: Title: `Food category`

Path: /food/%

Relatonship: Taxonomy term: Content using Food terms.

Contextual filter: (field_food_terms) Content: Has taxonomy term ID (with depth)

contextual filter settings: depth = 1 (use: this page override)

Override title: Food category - %1 This means, if we go to food/fruits, all items one level below fruits will be shown (all fruits)

Page: Title: `Food subcategory`

Path: /food/%

Relatonship: Taxonomy term: Content using Food terms.

Contextual filter: (field_food_terms) Content: Has taxonomy term ID (with depth)

contextual filter settings: depth = 0 (use: this page override)

Override title: Food subcategory - %1

There is no terms below, if we go to food/fruits/apples, all items with term name apples will be shown (only apples)

Use Views to override term paths

At the end you need to go back to: admin/structure/taxonomy/food edit each term and choose Use view override.


For each term you need to specify which view will be used to override, it's the main disadvantage of this solution.

enter image description here

Results

enter image description here


enter image description here


enter image description here


An example of article and blocks with relationship to the taxonomy.

enter image description here

  • If I need to specify a view for each term, the better option is to use TVI module. – deem Aug 12 '13 at 6:52
  • No, TVI allows to set a view override for vocabulary or each term. At least, in the latest version. However, I wrote module Taxonomy Views for making links taxonomy/[vocab]/[term]. It's in verification queue now on drupal.org. If you install it, you doesn't have problem with making different views for taxonomy term pages. drupal.org/sandbox/daroPL/2063497 – deem Aug 13 '13 at 6:51
1

Ok, maybe I don't fully understand the question.

Goal
Let's just assume the goal is to display, on taxonomy/term/%, a different view depending on which vocabulary that term is in. (whether there are pathauto aliases for this path, does not matter at all.)

Views page + contextual filters?
If you simply override the path with Views, this will be one views display for all terms, no matter which vocabulary - because they all share the taxonomy/term/% path.

Alternative I: Taxonomy display module
The Taxonomy display module allows to customize the "associated content" display on taxonomy term pages. It allows to use a different view per vocabulary.

On "manage display" for the term, enable "Custom display settings" for the "Taxonomy term page" view mode, then for this view mode, configure the "Term page display".

Alternative II: Display Suite + Taxonomy display + dynamic field
What I often do instead is use Display Suite, and use the "Dynamic fields" feature. I think you need to enable ds_extras, ds_ui (both shipped with Display Suite) and work your way through the settings. Ideally, you should also enable views_content ("Views content pane").

This allows to not just have a dedicated views display per vocabulary and view mode, but it also allows to freely place one ore more such views in the ds layout, along with other fields.

The Taxonomy display module will only be used to hide the core list of associated content. Possibly this could be achieved with a custom module, up to you.

Quick guide:

  • Download taxonomy_display, ds (7.x-2.*) and views. Enable ds, ds_extras, ds_ui, views_content, taxonomy_display.
  • Create a view with a "Content pane" display and an argument taking the taxonomy term tid. This has more to it than I currently remember, so good luck figuring it out :)
  • Go to admin/structure/ds/fields
  • Add a dynamic field, name it whatever you want, e.g. "Tagged content". As the entity type, name "Taxonomy term"
  • Go to admin/structure/taxonomy/categories/display (where "categories") is your vocabulary machine name)
  • Enable "Use custom display settings for the following view modes: Taxonomy term page". Save.
  • Go to admin/structure/taxonomy/categories/display/full
  • In "Term page display" vertical tab at the bottom, set Term display = Core, Associated content display = Hidden. Breadcrumb and feed is up to you.
  • In "Layout for categories in full", enable "One column" (under "Display suite"). Save.
  • Move the "Tagged content" up in the "Content" region.
  • On the dynamic field, click the cog-wheel icon, then "Select content", then in the dialog under "View panes" you can select the views display you just created. Configure the argument (Term id from url). Save.
  • Repeat for other vocabularies.
  • Make sure you disable the usual page view overriding taxonomy/term/%.

Alternative III: Taxonomy display + Display suite + Views content DS
The Views content DS is a bit more convenient than Display suite dynamic fields. Up to you.

  • Hmm, this thing looks promising! drupal.org/project/taxonomy_display I think to remember these same options have been in DS core in the past. Not sure about that. drupal.org/node/2071029 – donquixote Aug 21 '13 at 17:05
  • The Alternative: Display Suite + dynamic field worked out perfectly but is there a way to restrict the node listing on the term page. I could not figure out any option to disable that. I know the same can be achieved using the taxonomy display module, but due to some specific reasons I need to stick to the Display suite module only. Please suggest. – AkiShankar Mar 16 '16 at 13:19
  • I thought the term listing would already be disabled by using display suite? If not, I need to check in my old projects, next time I have a free moment. – donquixote Mar 16 '16 at 13:28
  • @AnandSBahuguna I checked again in a few sites I made in the past. Turns out I used taxonomy_display to hide the automatic term display, and then display suite to embed the view as a dynamic field. – donquixote Mar 16 '16 at 16:40
  • You could probably achieve the same (hiding the associated content list) with a custom module. Have a look at the code how taxonomy_display does it. Up to you. – donquixote Mar 16 '16 at 16:42

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.