What Is a Drupal "Content Type"? What Are "Fields"?

Definition:

A Drupal "content type" is a particular kind of content. For instance, in Drupal 7, the default content types include "article", "basic page", and "forum topic".

Drupal makes it easy for you to make your own content types. Custom content types are one of the best reasons to learn Drupal.

Content Types Have Fields

The most exciting thing about Drupal content types is that each content type can have its own set of fields.

Each field stores a particular bit of information.

For instance, suppose you like to write book reviews (a classic example). It would be nice to include certain basic bits of information about each book, such as:

  • cover image
  • title
  • author
  • publisher
  • publication year

Fields Solve Problems

Now, you could write your reviews as ordinary articles, and simply paste this information into the beginning of each review. But this would create several problems:

  • What if you forget a particular piece?

  • What if you change your mind about including, say, the publisher? How do you hide the publisher on all the old articles?

  • What if you decide you'd rather show some of the information at the end of the article? Or even in a sidebar? Or make the title bold? This kind of flexibility is impossible. You've been hard-coding the data in one particular spot in every article.

With fields, you solve all these problems.

You can make a "book review" content type, and each bit of information becomes a "field" attached to this content type.

Fields Help You Enter Information

Now, when you begin a new book review, you have a special, separate text box for each bit of information. You're much less likely to forget to enter, say, the author's name. There's the box for it right there.

In fact, each field has the option of being marked as required.

Just like you can't save a node without a title, Drupal won't let you save without entering text for a field that's marked required.

Fields Don't Have To Be Text

Did you notice that one of these fields is an image? Fields aren't limited to text. A field can be a file, such as an image or a PDF. You can get additional kinds of fields with custom modules, such as Date and Location.

You Can Customize How Fields Display

By default, when you view your book review, each field will appear, with a label. But you can customize this. You can rearrange the order of fields, hide the labels, and even use "image styles" to control the display size of that book cover.

You can customize both the "Default", full page view and also the "Teaser" view, which is how the content appears in listings. For instance, for listings, you might hide all the extra fields except the author.

Once you start thinking about listings, though, you'll want to dive into Drupal Views. With Views, you can build custom listings of these book reviews. See this article for examples of Views.

How Do I Add Content Types?

In Drupal 6 and earlier versions, you needed to install the Content Construction Kit (CCK) module in order to use content types.

With Drupal 7, content types are now included in core. Log in as an administrator, and, on the top menu, go to Structure -> Content types -> Add content type.

Making custom Drupal content types is extremely easy. You don't need to write a single line of code. On the first page, you describe the content type. On the second page, you add fields. At any time, you can edit the content type to add or remove fields.

Content types are one of the most powerful features Drupal has to offer. Once you start thinking in content types and Views, you'll never go back to basic pages.