A simple request

You know the story. You build a Drupal site. It's amazing. Then the client asks for 2 simple features to be added. And you can't deny that they are reasonable requests. If only you'd known about them when you started!

The site displays photos in a dozen categories. A basic taxonomy chore. On choosing one of the categories from the menu, the user is shown a grid of thumbnails which click through to a page with a larger version of that photo and an optional description.

To accomplish this, I used CCK to made a new content type with 4 fields: Title, Image, Description, and Category - this last a drop-down option selector for the taxonomy terms.

Then I set up the Taxonomy; just one vocabulary with 12 terms, and then a Menu with items that link to each of those terms (e.g. /taxonomy/term/8).

I used Views to make a page to display the thumbnails and had the Views page overide /taxonomy/term/*.

Then came the first reasonable request: text displayed above the thumbnails describing the category. Easy enough - this text can be entered in the taxonomy term description field. I tried getting this to display by changing my thumbnail grid to a block and making another View block that grabbed the taxonomy term description, and placing both of these blocks on the /taxonomy/term/% pages, but apparently a block can't tell what page it is on and so it can't filter by term.

The interim solution was to ax the Views and go back to the default taxonomy term pages which I styled with CSS to show the photos in a grid. Out of the box and nearly perfect, except I was sizing down the full size pictures instead of using View's nice thumbnails so the page load was much bigger than it needed to be.

Then came the next perfectly reasonable request: to have the images appear in a certain order, or in other words to be able to sort the display. By default Drupal displays the taxonomy term items in reverse chronological order. I searched extensively for a solution, first by looking for a template to modify, then thinking that it could be done in the URL (something like /taxonomy/term/*?sort=sort_field), but all to no avail. I even considered modifying the DOM with jquery (which I'm sure can be done, but seems somehow too convoluted to be a good solution).

The first step here is to add a Sort field to the content type using CCK, but as described above, I could not get Drupal to sort on that field. So it was back to Views and it was easy enough to add a Sort there, but I still had the problem of showing term-aware Views blocks.

The answer I finally came up with was using the Panels module. And once again it was quite simple to activate Panels' built-in taxonomy/term/% override page and to place the description block and the thumbnail grid Views on it - but it was difficult figuring out just how easy it was!