
Customizing Drupal - Part 5 Content types, CCK and Taxonomy
Now that our site has content, menus, users and access control lists, I think we need to start to add additonal functionality. Today we are going to create a new content type for our site from scratch. All authenticated users will have access to this content type, including the ability to make new content. Then to wrap it up, i will show you how to make a nice view for the content.
In my case, I'm going to create a new content called User Article. This will be a place where users of the Linux Basement website can come in and create their own tutorials, write a review of a distro, or tell how to install their favorite package. However, keep in mind this tutorial could pertaint to any new type of content you want to create. For instance, it could be a database of customer accounts, or job openings.
For the purposes of this tutorial, please make sure that you have the CCK and Views module installed. These can be found over at Drupal.org.
The first thing we need to do is create our new content type. To do this, log into your site as the administrator, and go to Administer-->Content Management--> Content Types.

Your content t ypes will look slightly different, because I have already created several new ones, but you will notice also that some modules create their own content types, such as the Audio Module. We want to create a new content type. To do so, click on the tab "add content type." Here, I will name the content type, and give it a machine readable name, which I often use the same for both, except I keep the machine readable name all lowercase, with an underscore for spaces. Then give a description of the content type.

There are other options that are pretty self explanitory, such as whether or not you want comments on by default for this content type. Once you've decided on the settings, click "save conent type" at the bottom of the page. Now you will notice on your Content Types list, your new content type is listed! Great! Also notice that if you go to "create content" in your navigation block, you will see your new content type there.

Now lets add some additional functionality to "user article" content before we test it out. For this, we are going to use CCK, and create different types of user articles, so they can be sorted later by the different categories. Go to Administer-->Content Management-->Content Types and click on "edit" next to "user article". You should see a tab at the top that says "add field" go ahead and click on that. This is where you will begin to realize the power of CCK. The Content Creation Kit allows you to make custome input fields in our content nodes. The possibilities are near endless, and you can extend the functionality with more modules. For now however, we are going to create a simple text dropdown box.

Create a machine name for your database, mine will be article_type, and for now we are going to select "text" "select list". Now click "create field" at the bottom of the page. This will take you to the field settings page for the new field you created. Here, we need to label our field. It will default to the machine readable name, but I would change it slightly to make it easier on the eye. Also note, by default we have a select list, but you could use check boxes.
Next, add some help text so that the user knows what this field is for. In my case I put, "Choose the type of article you would like to create. If you do not see it here, choose other."

In the Data Settings portion of the site, lets check "required" so that the user has to make a choice for this field. Now lets look at Allowed Values list. This is where we will put the values for our drop down box. If you are using an HTML editor like FCKeditor, make sure you click "source" before entering the values. Enter the values one on each line. When you are happy with the selection, hit "Save Field Settings"

I'd like for users to have the ability to "free tag" the articles so they can be sorted by category, much like many blogs do. To do this, lets go to Administer-->content management-->categories. Click on add category. We are going to create a category specifically for User Articles. Lets fill out the form.

Give your category a name. I'm going to keep it simple and call it "topic" then give it a brief description so you can remember what it is for. More importantly is the help text, which will tell a user what to put here. Now pick which content type will have this attribute, and then for our needs, lets disable hierarchy, allow multiple, and require a user to put SOMEthing in the field. Then click submit.
Excellent. Now we have the abiltiy to categorize, and free tag our articles. Lets go ahead and create a test article, so that we have something to work with.

Great, we've done it! But wait, where the heck is the article? Well, if you published it, it could be on your front page. In my case, it is in no man's land, because my front page only consists of the linux basement podcast. I need to create a new view, specifically for the User articles. But that is all for this week. Next week we will delve into the world of Views!
