Back to the front page
Two ways of creating a product list
February 16th, 2008
Filed under Drupal
(Part 3 of a series on setting up a corporate website in Drupal. Part 1 Part 2 Part 4))
I’d like the site to have the following functionality:
- A main Products page which has a bit of intro text and then a list of product types. These should be links based on the first level of the Product vocabulary.
- Each link should take you to a page for that product type, again with some intro text, a list of sub-types and the first 10 products in that type ordered by most recent
- Each link from an individual product should take you to the page for that product, showing the description and brochure to download
I set up the individual product pages and downloads in Part 2, so now I have to pull together the pages for each type of product.
It turns out that creating a list of sub-types, rather than individual products belonging to sub-types, isn’t as trivial as you’d think (even using the Views module: see the discussion here). In Drupal speak, that’s creating a list of terms, rather than nodes. I came across the Taxonomy List module which works in conjunction with the Taxonomy Image module to create lists of category terms with descriptions and images. After installing both, I could associate an image with each category term through the Content management/Categories tab and set some options, including html tags for the images under Site configuration/Taxonomy Image. Options are set for the Taxonomy List under Site configuration/Taxonomy List. You access these lists using the mysite.com/taxonomy/vocabulary/#, where # is the id number of the vocab in question (find it by looking at the end of the url given by the Content Management/Categories/List terms link). Unfortunately, I couldn’t get the images to display, just the link – as described here you need to change some code in the Taxonomy List module file, after which it works perfectly.
I gave that page (/taxonomy/vocabulary/1) a nice clean url in the Site building/URL aliases tab and an entry in the Menu under Site building/Menus. The intro text is given by the description of the Product category – not perfect, but saves me creating a custom page and fiddling around with the php.

Terms further down in the hierarchy are all listed in the table that Taxonomy List produces – the Flat or Hierarchical option controls if they are indented or not. I couldn’t see how to list just one level of terms.
Each link takes you to the page for nodes under that term, with the url /taxonomy/term/#. You can give that page a fancy alias too (e.g. /product/typeofproduct), and the products belonging to that type an alias too. (That’s a lot of work. Is there a better, automatic way to create aliases? I’ll get to that soon).
Taxonomy List and Image are pretty well executed one-trick ponies. But there is another, more flexible way to create a terms list, and that’s using the Views module. The crucial settings are to create a view that outputs to a page, filtering nodes using One of Terms for Products and an argument type of Taxonomy Term ID returning Summary values (unsorted or sorted ascending/descending). This generates a flat list of terms without preserving hierarchy, returning only those terms that have associated nodes (in my example, only those product types which have products associated with them). To control the hierarchy, you can deselect some of the category terms in the Filter, and then specify a depth to search by in the Option box. For example, selecting the top level terms and specifying a depth of 1 returns the top level terms and one level down of sub-terms. Choose 0 to just return the top level.

Views does lots more, including sort orders, filters, arguments passed from urls and custom text before and after returning content. I was able to pull together a custom product list showing a list of product types followed by 5 of the most recent products by making certain views available as blocks, and setting these to display on one particular page:

Next: Investigating aliases
zoejessica.com » Blog Archive » Drupal set-up and modules for a corporate website commented on February 17th, 2008 at 9:15 am
[...] 2 of a series in setting up a corporate website with Drupal. Part 1 Part 3 Part [...]
zoejessica.com » Blog Archive » Choices, choices commented on March 9th, 2008 at 8:24 am
[...] 1 in a series about setting up a corporate website in Drupal. Part 2 Part 3 Part [...]