CCK Module Basics

Printer-friendly versionPDF version

Content Construction Kit (CCK) is one the most important and at the same time most mystifying features of the Drupal platform. In this drop I'll provide a high level overview explanation of CCK and why you might want to use it on your site.

What is CCK?

CCK is a contributed module that allows you to:

  1. Add fields to an existing Drupal content type
  2. Create new custom content types

Drupal Content Types

It's important to understand a bit about Drupal content types. Drupal comes standard with blog, page and story content types. The main difference between these content types is the way they are organized by the system.

  • Blogs are associated with a particular user and will be listed at 'http://www.yoursite.com/blog' which shows all blog posts by all users. Blogs will also be listed on page that shows only posts by a particular user. The url for those pages may be something like 'http://www.yoursite.com/blogs/[username]'.
  • Pages will simply have a url " and not show up in any lists unless you take some sort of action to do add them to a list.
  • Stories are like pages except that they are automatically promoted to the front page.

The common thread across these three types of content types is that by default they contain two fields called Title and Body. But what if you want to expand a content type to add more fields? That's where CCK comes in.

Adding Fields

CCK allows you to add one or more fields to an existing content type. There are a number of reasons why you might want to do that. You could add fields to improve your workflow. If you're publishing video you might want to add a link to the video each time you post. Adding a field that is required when you submit ensures that you won't forget to add the link. See my post Adding Fields With CCK for an example.

You could also add a field to make it easier for you to organize or theme your content later. When a piece of information is entered into the body field you can't really sort that piece of information or use it if you want to create a list using views. But once a piece of information has it's own field you have much more flexibility. Using the video publishing as an example once again you might add a field that displays the duration of a video that is linked to a post.

Creating New Content Types

If you want ultimate flexibility in customizing your content types then you can use CCK to create a whole new content type that meets your specifications. Imagine that you want to be able to add information about your favorite DVDs to your Drupal site. The title and body fields probably won't meet your needs. You might want fields that list the Director of the movie, the top stars, release date, rating, an image, a link to the trailer and more. CCK was tailor made for things like this.

How Does CCK Work?

Many people are confused about how exactly to put CCK to use on their own website. You get started by downloading the module from http://drupal.org/project/cck but you will likely have to do more. The power of CCK is in the types of fields that it allows you to add to a content type. The contributed module includes several standard fields (like text and node reference) included but many of the fields you would want to add to your content type must be downloaded and enabled separately.

Here are some additional fields that are listed on the CCK module page on Drupal.org:

  • Computed field: lets you add a PHP-driven "computed field" to CCK node types
  • Date: creates an ISO or unix timestamp date field
  • Email: validated email field
  • Image field: an image field
  • Link: a URL field

There are many other fields that you could use to customize your content type. These can be found in the CCK modules section on Drupal.org. Some of the interesting fields that you might want to add are listen below.

What Next?

Your new content type is basically a list of fields that are ordered a certain way. Creating a new content type and adding fields is only part of the work you'll need to do in order to make CCK work for you on your Drupal site. Each field that you add has settings that must be attended to. You may also be concerned with how the new content type is displayed when you publish a node. The Contemplate module allows you to adjust the layout and customize the appearance of content types. If the content type you have created is brand new then you will need to use the Views module to create a page, block or RSS feed for the content.

Another thing to consider when creating a new content type is the path to the nodes that you create. By default content created on your Drupal site will have a path that looks something like 'http://www.yoursite.com/node/24'. If you're submitting the DVD content type that I mentioned above you might want to the path to be something like 'http://www.yoursite.com/dvd/[movie-title]. That's why I highly recommend the PathAuto module for automatic node url creation.

CCK Screenshots

These are screenshots that show what CCK features look like in the adminstration section of this site.

CCK FieldsCCK Field Display SettingsCCK Node Submission Fields

Bookmark and Share Bookmark or Share Post

Comments

Anonymous's picture

Thks for the writeup.

Please do not carry this common miscunception, though : since D5, custom content types are handled by core's node.module, not CCK, which 'just' lets you add fields on the content types that exist on your site.
You don't need CCK to create content types, and the expression 'a CCK content type' that pops up frequently (not in your paper, though), has no meaning.

learnbythedrop's picture

It's true that you can create a new content type with the core features. But the new content type you create via the core functionality is still limited to the title + body structure until you add the features provided by CCK into the mix. There are other types of modules and techniques that a person could use to customize a new content type but I've found CCK to be the one that works best for a non-programmer like me.

Anonymous's picture

This is a useful technical clarification. I had forgotten this, although I vaguely recall the issue on d.o

But I am not sure it makes any difference to end users because if a non-programmer wanted to create a new content type for a site, CCK is how they would do it.

Anonymous's picture

Does not make that much difference in the end, except :
- it's always best to give users the real picture of who does what - does pay on their overall drupal mojo.
- managing CCK issue queue, I get to redirect issues and say "CCK doesn't handle content types" at least 5 times a week and I really could do without :-)

Anonymous's picture

Hello, Thanks for creating a very useful site.

The CCK basics should include how to change content type such as a content type created as "page" to "story"

Also a guidance on how to include the field for taxonomy in content type such as "page"

Good luck for your efforts

Anonymous's picture

One thing I keep struggling to do with CCK is just add plain text on the page.

For example, I'm making a Job Application content type, and am using the File Attaachments area for people to upload resumes.

How can I add instructions that say like:
Use the file attachment tool below to upload a Resume and Cover Letter.

I'm looking for just a field type of "plain text (not really a field at all)"

any suggestions?!

thanks again!

learnbythedrop's picture

A plain text field is really a field. When adding you select a field type of "text" and choose either the text field or text area (multiple rows) widget choice in the drop down box next to the "text" field choice. You can fill out a default text for the field and then after saving the new field you have added you can go to /admin/user/permissions and allow users to view but not edit the field. Then you will have an additional field with the text that you want on your submission form.

Anonymous's picture

Thanks for the reply! - but that doesn't seem to work. When I make it so they can't edit the field (even when they CAN view it), it doesn't get displayed on the Create Content form. :/

You are talking about while using the Content Permissions module, right?

learnbythedrop's picture

No, I wasn't referring to the content permissions module, just the standard features within CCK. The easiest ways to add instructions for any field is to use the "Help Text" field that is displayed in the configuration for any field that you add using CCK.

Anonymous's picture

I'm pretty new to Drupal and am still learning about these core modules. Your review was the easiest to understand, now I finally know what this so talked CCK is about.

Unfortunately I wasn't able yet to make a few fields I created to be shown on posts edition page.

Post new comment

Google Friend Connect (leave a quick comment)
loading...
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.