Howto: Node-based galleries with CCK and Views

Most Drupal-based Gallery solutions use Taxonomy to build sets of images; the resulting galleries are Taxonomy pages that can be easily maintained and expanded, but are not available to the node system: They can't be referenced from other nodes through a CCK node reference field, they can't be tagged, they don't accept comments and so on. Thus in many cases a node based photo gallery would be preferrable - if it would exist.

As usual, Drupal can solve this problem with a set of core and contributed modules. This Howto is a transcript of the screencast Photo galleries with Views Attach by Jeff Eaton, where Jeff demonstrates how to to create node-based galleries with CCK and Views. In the end, this is one of the most advanced approach to publish images with Drupal, so there are tons of reasons to educate the Drupal community about this approach.

Notice: This approach is based on the Content Construction Kit (CCK) and won't work with the contributes Image module. Image module offers adifferent gallery solution that is based on Taxonomy and views.

Step 1a: Create Content Types

Node-based image galleries require two content types that need to be created via ./admin/content/types/add:

Gallery - a simple "container"-like content type for galleries

Photo - imagefield-based content type for photos

These content types might be created with different names (e.g. 'image' instead of 'photo', or 'photoset' instead of 'gallery'), but the required views have to be adapted to those different names. Please note: To create new content types, you have to be logged in with proper permissions (e.g. user #1).

Step 1b: Create ImageCache Thumbnail Action

Go to admin/build/imagecache and create a new preset named 'teaser_thumb'.

Add a new 'Scale' action

Set the width to be 150 pixels

Clear the height field

Save the action

We'll select this ImageCache action output in the View for the gallery

Step 2a: Creating the Gallery Content Type

Go to ./admin/content/types/add, create a new content type named "Gallery". Save it with default values, you don't need to change anything so far. However, feel free to adjust parameters like Submission form settings, Workflow settings, or Comment settings to your liking; this will not harm the following steps in any way.

Step 2b: Creating the Photo Content Type

Go to ./admin/content/types/add, create a new content type named "Photo" and save it. Add the following two fields:

Step 4: Add Theming

add <a href="node/add/gallery">Add a gallery</a> within <?php if ($admin_links): ?>

Rescan Template files

Possible extensions

So far this tutorial simply tried to transcribe Jeff Eatons screencast; however, there's a lot of room for improvements and extensions.

Getting lots of images into the galleries

Filling galleries with images might require bulk uploading of files onto a server. That is usually done by an administrator. But what if users are supposed to be empowered to build image galleries without a sysop or webmaster handling the files? That's where additional contributed modules might come in handy.

Comments

thank you very much for this post. i was looking for a handy image gallery solution, and i think this is the only suitable way in drupal without using taxonomy. it works very well, but how can i create a several menue item with views, so the gallery isn't displayed on the start site. i want to call the menue-item for example "imagegallery" ?

How can I add primary links to my galleries? Since we were using nodes content view, pages view -normally used for creating paths- wasn't touched. Any help will help greatly not only me but a bunch of other users.