Using CCK, Views and custom theming to show self-defined nodes

For one of my latest projects, I needed to create node relationships. The client wanted to create nodes (“Photos”) that have a common parent node (“Series”).

I was contemplating to use OG, as it’s are real powerful module, but decided against it, as the requirements were much smaller. Instead, I decided to use the node_reference field that’s part of CCK to create relationships, which works like a charm. I didn’t run into the problem that these relationships are just pointing in one direction. On the frontend, both items were linked with each other.

The bigger challenge was displaying the Photos in a Series. I previously used Panels for grouping several views and was attempting to do the same thing in this case. After a lot of trial&error, I decided that Panels for Drupal 6 isn’t quite ready. The main reason I decided against Panels was the missing feature to use node overrides for different node types.

I was able to create a view that displays all photos in a series, using the Views preview to manually try out different Series node id’s (nid). The missing piece was to display both the Series itself and the view to display related items, something that I would have liked to use Panels for. The solution to my problem was a little bit of custom theming. I created a separate template for series using a duplicate of node.tpl.php. Then, I added a function to display a view in a template file (take from here:


Let’s dissect the parameters of that function:

  1. The hard-coded view name (defined by myself)
  2. The display type (I selected default, but this could also be ‘page’ or ‘block’
  3. Arguments passed into the view ( arg(1) makes sure the view knows the nid)

Here’s a screenshot of the view “series_photos”:

Conclusion: I usually try to get around custom theming. Not because I’m too lazy to do it, but because I’d like to keep as much as possible defined in the database. This solution however worked out quite nicely with only minimal theming.