Custom Content Types in Drupal

On April 26, 2008, I gave a presentation at LinuxFest Northwest on how to create custom content types in the Drupal web-site content management system. The talk was recorded on video, and is available for viewing on-line (the video page says it is "Part 1 of 2", but it actually has the entire talk).

I also gave the same (or very similar) talk at Drupal Camp Vancouver, on May 9, 2008. And I gave an expanded version, as two separate talks, at Drupal Camp Seattle on June 27th, 2008. There are videos for both parts available: CCK module and Views module. If you'd like me to come give this talk to you, please contact Poplar ProductivityWare.

It is somewhat difficult to read the overhead screens in the videos. So, below you can find the information from the Background Information, Outline, and Planning sections of the original talk, as well as screen shots from the rest of the talk. You may want to refer to these as you watch and listen to the talks.

There is also an "extra credit" section below, which didn't make it into the video.

If you are unfamiliar with Drupal, you may also want to check out the Background Information before viewing the video.


Background Information

  • For basic Drupal information, including terminology, installing, basic site building, and links to a lot of other information, read my Drupal Cheat Sheet article, elsewhere on this site.
  • Drupal versions and modules used for this talk - get these at drupal.org:
    • Drupal 5.7 with built-in "PushButton" theme
    • Content Construction Kit (CCK), along with its separate sub-modules ImageField, and Date
    • Views, along with its separate sub-module Calendar
  • Slides and/or videos of other Drupal talks at LinuxFest Northwest 2008 can be found on the LinuxFest Northwest web site, and on the Drupal Camp Vancouver presenters' notes page for that event.

Outline

  1. Planning data/content types
  2. Creating data/content types - Content Construction Kit
  3. Creating vocabularies/categories - Taxonomy
  4. Data entry
  5. Displaying data/content types - Views and Blocks
  6. Menus [note: there wasn't time to cover this in the talk]

Planning

Example: Web site for an organization that offers art classes, taught by several instructors.

Types of information/content:

  • Instructor: name, bio, photo, subject areas (drawing, painting, etc.)
  • Course: name, description, subject area (drawing, painting, etc.), age level (elementary, middle, high school, adult)
  • Scheduled Class: course (link/reference), start date, end date, start time, end time, cost, instructor (link/reference)

Information Displays (Views):

  • List of upcoming scheduled classes - sort by start date
  • List of courses - allow viewer to filter by subject area and age level
  • List of instructors
  • Scheduled Class detail - links to instructor and course description
  • Instructor detail - show list of upcoming classes this person is teaching, and what they have taught in the past
  • Course detail - show when this course is scheduled

Screen Shots for Creating Content Types

(Click on a link or small image to see the screen shot.)


Screen Shots for Taxonomy

(Click on a link or small image to see the screen shot.)


Screen Shots for Data Entry

(Click on a link or small image to see the screen shot.)


Screen Shots for Views

(Click on a link or small image to see the screen shot.)


Adding Block Views to a Page

This didn't make it into the video - it's the "extra credit" section on how to make a view show up in a "block" on a page of your site.

Here are the steps for making the "Upcoming Classes" section appear on the Individual Instructor page (see screen shot of Individual Instructor page above):

  1. Whenever you enter content for an Instructor, be sure to give it a path (URL) of instructor/something. Screen shot:
  2. Define the view. This will be a "block" view, rather than the "page" view demonstrated previously in the talk, but the fields section and filters work the same as the previous view. It will need an "Arguments" section, though, which is new -- what this will do is make it so that only the classes being taught by the particular instructor we are looking at are shown. We use some special "Argument Handling Code," which finds the instructor's internal Drupal ID number, and tells the view that this is the instructor we are interested in. See the Contextual View Blocks Snippet on drupal.org for more information. Screen shot:
  3. Once that view is saved, it will appear in the Blocks management screen. So go to Administer / Site Building / Blocks. Find the "Upcoming Classes for Instructor" block in the list of blocks, assign it to the "Content" region of the page (which will display it below the body and fields of that piece of content in most themes), and click "Save Blocks". Screen shot:
  4. Finally, we need to make it so this block only appears on Instructor pages, not every page of the site. To do that, click Configure next to the "Upcoming Classes for Instructor" block, and tell Drupal to display this block only on pages with URLs like "instructor/whatever". Screen shot:

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
three plus equals eleven
Solve this math question and enter the solution with digits. E.g. for "two plus four = ?" enter "6".