Creating new content types

We have looked at two different content types provided by Drupal – Stories and Pages.

Later you will meet other content types. If you enable Drupal's blog functionality you will find that Blog entries are a separate content type. This is as you would expect, after all a blog entry isn't a page and it isn't really a story, it is something else, so it needs a new content type to represent it. If you enable forums you will discover the Forum topic content type.

When you develop your website you might find that you have your own custom content types. On our example website, cookiewiki.com, which is a recipe site, we will surely need our own Recipe content type for entering our recipes.

Our recipe site might also carry information about cooking equipment, with a collection of articles about how to choose a good knife, what to look for when purchasing a wok, etc. So we might need an Equipment content type. There might also be an Ingredients type for articles about ingredients (how to select a good steak, what does fenugreek taste like etc).

Using different content types has several advantages:

  • It acts as a top level classification of our nodes into fundementally different types of content.
  • You can use different layouts for different content types.
  • You can control which users can edit each content type (you might let certain users add Recipe items but you would not let them edit the Page items which make up you main site pages).
  • You can customise the submission form for different content types in various ways.
  • You can add extra information fields to some types of content.

Deciding when to create content types

Content types are very useful, but it is important to design them carefully. It is very difficult to change content types once you have started adding a lot of content.

It will often be obvious when you have a new content type, if you find that you have some nodes which don't belong to any existing type. The following factors often indicate the need for a new content type:

  • The content is clearly a different type. Having a separate type for Recipes is pretty obviously a good idea.
  • You want to take advantage of some of the features listed above (for example, we might want to format recipe pages differently from normal site pages). Even if you only think that you might want to do these things in the future, it is worth setting up a different content type.
  • If content needs it own unique extra fields, then it is almost definitely a new type.

Avoid using content types to divide content into sub-categories, if they are all essentially the same type. For example, we might want to distinguish recipes from different parts of the world, eg French dishes, Chinese dishes etc. These are not separate content types, they do not differ from each other in any of the ways listed above.

Implementing these as separate content types would be a bad idea. You would end up with a large number of content types which did not differ in any way. Everywhere you needed to set up anything to do with content types, you would find yourself setting identical parameters for lots and lost of types, which is very tedious and error prone. They are just sub-categories of recipe content, and there are better ways of representing this (for example, the Taxonomy system).

Ultimately, it can boil down to a matter of judgement. For example should Equipment and Ingredients be separate types, or should you have one type (eg Articles) to cover both? It depends whether you expect to ever use any of the features you get from separate content types. I can't answer this question for your website, but for cookiewiki.com we will keep Equipment and Ingredients as separate content types – we might wish to add extra unique fields to these types later.

Creating a new content type

To create a new content type, go to Navigation | Administer | Content types and click the Add content type tab at the top of the page.

In the Identification group you need to provide:

  • Name, the user visible name fo the type. This is just what is displayed when you are choosing a content type. Choose something simple and obvious (and singular), eg “Recipe”.
  • Type, a machine readable version of Name. This is used for constructing URLs based on the content type. Normally just choose a lower case version of the name, with any spaces replaced by an underscore character, eg “recipe”.
  • Description, an optional description of the type. If your site is likely to be used by other people with content creation rights, fill this out to remind them what the type is for.

The Submission form settings group alows you to control the behaviour of the form used to create recipes.

  • Title field label, Body field label allows you to customise the submission form. By default our new Recipe submission form has a title field labelled “Title” and a body field labelled “Body”. Try changing “Body” to “Recipe”. When you add a new recipe, instead of being asked to type in the Body you will be asked to type in the Recipe. It only changes the label on the form, but it can make it more user friendly.
  • Minimum number of words, if you wish you can prevent users submitting very short (or empty) content. We could consider using this on our recipe site, a recipe of less than 50 words is probably not a proper recipe.
  • Explanation or submission guidelines allows you offer advice or guidance on submitting content. At the very least, we should warn users not to try to submit a recipe of less than 50 words.

The Workflow settings group controls the default settings of the Publishing options for this content type (ie whether or not Recipes are published, promoted to the front page or sticky).

These settings can also control whether editing the content will create a new revision by default.

The Comment settings group controls how user comments appear for this content.

  • Default comment settings determines whether comments are permitted for this content type, by default. These settings have the same meaning as the Comment settings in Content settings.
  • Other settings. There are many other settings, relating mainly to the way the comments are displayed and organised. The form itself provides a good explanation of what these fields are for, experiment with these until you are happy with the result.