Understanding Drupal 6: Part 1 - Content Types

This is the first in a series of blog posts whose goal is to easily explain the important parts of building your own custom Drupal website. As the most important part of any website is displaying content to your viewers, we'll start by discussing what a content type is, how to create one, and how to display it to viewers of your website.

Important: Before you attempt to build any content types, you'll want to download CCK (Content Construction Kit) and install all of the modules it provides. This module is essential for building content types within Drupal.

What is a Content Type?

In Drupal, a content type is a vessel for you to display a customized form of content to the visitor. Perhaps you want to display information about a book you've created, but you don't want to put all of that information into a WYSIWYG. Or, perhaps you want to display information relating to an event in a standardized fashion. With a content type, you can create unique fields of different types that you can then display on your website as needed. Then, you can create nodes from those content types begin building your site.

Creating a Content Type

To take an example from above, let's say you want to create an event content type. There are a number of fields you may want to show, such as the start date and time, the location, an event price, and directions to the event.

Once you decide the fields that are necessary, it's time to decide how to store them. CCK allows for a number of different field types. In this example, we'll assign the following field types to each field:

  • Start Date/End Date - Date field (You will want to download the Date module. This gives better date functionality, such as the addition of a date popup selector)
  • Location (Text field)
  • Price (Float)
  • Directions (Text Box)

You have the ability to create all of these fields within the "Manage Fields" section of the content type form. You can also house different sets of fields within groups to make it easier for the user to understand what they need to fill in.

Displaying a Content Type

There are generally two different ways in which content can be displayed on a Drupal site. The first is in how you display the actual node, while the second deals with displaying nodes in a teaser like fashion on a landing page.

Drupal will automatically set up the node to display custom fields in label/field format. However, you may want to style your node with a different HTML structure and CSS. Therefore, it's just a matter of creating a new node-nodetype.tpl.php file, then displaying all fields through the $node object.

In order to display a certain amount of nodes on one page (such as a landing page), you'll need to use another great Drupal module called Views. This module essentially allows you to create your own SQL queries via a GUI (Graphical User Interface) editor, and does a superb job. It's so good, in fact, that I'll be dedicating my next blog post to "Understanding Views", so come back next time to learn the methodology behind displaying your nodes in a custom, dynamic fashion!

About the Author

Ben has been seriously working with websites since he was about 15, when he created a dynamic website to list results and user profiles for the Cross Country and Track and Field community in his county. Ever since, he has been enamored with web...

 
blog rss banner
 

Categories

View All

Testimonials

"Unleashed Technologies came in under budget and blew us away with the quality of their work. It was refreshing! Especially when most others in this field over-promise and under-deliver!"

Lawson Owen
Proactive Dealer Solutions

“It was a pleasure working with Michael Spinosa and his team from Unleashed Technologies.

Jordan Sopher
Eyemaginations, Inc.