I am using Drupal 7.14 and I'm wrestling with filtering my content type based on taxonomy terms. I have a solution but I'm sure there must be a better way!

I have a content type called News. It has a taxonomy field so I can categorize the postings to it. I currently have 4 different taxonomy terms.

I also have a view that shows a page with all the News item teasers and links to the full article.

I have a menu on the side of the News page with links to each of the categories. Clicking on one of these links will show a page of teasers for that particular taxonomy term.

I have implemented the above as follows: In my News view I have added a display page for each of the taxonomy terms. On the same form I changed the "Page Settings" to set the path to the path of the taxonomy term (this overrides the default taxonomy view for the term). I also change the "Filter Criteria" and add a filter for the particular taxonomy term.

I then built a menu using the taxonomy term paths and made it appear on the News content type pages. Each item in the menu points at its taxonomy term path. When the user clicks on a menu item it correctly shows the view filtered for that category. Note: it does not show the default taxonomy term page because I set the path to the taxonomy term in my view and this takes priority.

I have also overridden the template for my view by adding a custom template file called views-view-fields--news.tpl.php. This template is used for the full view and each of the filtered views.

The above does work but is there a better cleaner way? It is quite tedious to add a new category as I need to manually update the view to add a new display for the new category and I then need to update the menu of categories.

Many Thanks.

3 Answers 3

  1. Create a view with an exposed filter for each News category.
  2. Under its settings, in Admin, there is a Filter identifier which can be changed. This goes after ? in the URL.
  3. Build your menu to link to the new view and add the category after the filter identifier.

The benefit of this is you can do it with any view so your tpl will work. And users can change category quickly using the dropdown menu. Or you can hide the exposed filter with CSS and make them use the menu.


You could also go ahead and let it link to the taxonomy term page, and then customize that view. I believe that would eliminate the need for manually entering categories.

Additionally, you could use contextual filters and set it to display a list of all terms when filter is not in URL.

  • Thanks for the reply. Yeah I investigated this but the default view for the taxonomy term does not use my customized news template file (views-view-fields--news.tpl.php). I didn't really want to maintain two different template files for what is essentially the same thing. The contextual filters sound interesting, I'll look into them. Thanks!
    – hgg
    Aug 20, 2012 at 17:35

When you add a new category your view is able to pick that up and dynamically create all the things you need here. Let views do the heavy lifting.

I am not familiar with your view but it sounds like it just needs tweaking to select all categories instead of the four you currently have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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