Now that the preparations in the previous section are complete, this section of the guide will help you construct a custom "Content Type" called Article using the CCK module, as well as a variety of custom fields.
After completing the CCK section of the guide, you will have developed skills working with CCK which you will be able to re-apply to your own site in the future, creating your own custom Content Types, and any type of field your Content Type needs. You'll also have gained an understanding about how URL aliases (also known as Paths) work in Drupal, as well as how to make Custom Breadcrumb links for your content types.
Begin by going to Administer > Content management > Content types (admin/content/types) and clicking the "Add content type" link at the top of the page.
ArticlearticlePromoted to front page option.The custom fields will include article_teaser_text to serve as a custom-written teaser which will be displayed only in the context of teaser views of the content but not on the full article, and article_subtitle, which is a sub-title about the article that will only be shown on the full version of the page but not in the teaser. You can of course add as many additional fields as you need.
article_teaser_text, and for Label enter: Article Teaser.Text and press "Continue".Text field, and press "Continue".Text area (multiple rows). Keep in mind that with most WYSIWYG editors, setting a text field to be "multiple rows" usually activates the editor on that text area, which is probably excessive in this case (though your WYSIWYG settings page may allow you to selectively disable these). Generally for a small text field of this sort I don't recommend HTML, and especially not WYSIWYG. If you change your mind you can always adjust this setting later.Required option, and enter a number for Maximum length such as 100 (it's usually ideal to set a maximum number of characters for the teaser to ensure it fits within the area you allot to teasers in your theme, and to enforce keeping teasers short and to the point for your readers). It's worth noting that Maximum length can only apply to a Text field kind of field -- the HTML textarea tag that the Text area (multiple rows) option creates is not capable of having a maximum length set (which is a limitation of HTML itself, not Drupal - you can however impose a maximum length on this tag using JavaScript).Filtered HTML (again not recommended, as the HTML counts towards the character limit, not to mention the purpose here is just a short bit of teaser text so ideally it should be kept simple... save the fancy stuff for the full article).article_subtitle, and for Label enter Article Subtitle.Text and press "Continue".Text field, and press "Continue".Required option, but you can choose to make this optional if you prefer.Hidden, Teaser to Hidden, and leave Full Node set to Default.Hidden (the reason for this is because this field will "only" ever be used within the context of Views module, which will call it up in its own way, so we want to hide it in every other case).Before continuing, it will help you to understand a bit about "how" URL paths in Drupal work, and how that applies to what you're trying to accomplish in following this gude. The terms URL, path, and alias are often used interchangeably in Drupal.
Our goal in this guide is to set up URL paths like this:
example.com/articles
This will be for the index/listing of all the articles, and will be handled by the Views module, covered in a later section of this guide.
example.com/articles/name-of-article
This is the path for the pages (nodes) created for the "Article" Content type. Nodes receive their URL paths through the Path or Pathauto module. Path is a module that comes with Drupal by default and lets you manually make up URLs for pages as you create them, while Pathauto is an add-on module which automates this process, following pre-determined settings which you customize ahead of time before creating the content. In this lesson the Pathauto module will be used.
Although they appear "connected" (similar to how files are placed inside a folder), the example.com/articles path made by Views module and the example.com/articles/name-of-article paths for content are not actually connected to each other internally (however, so long as they're set up correctly, they will "appear" and function as if seamlessly connected to each other).
Think of it along the lines of the "files inside a folder" analogy. The files are the Article content/nodes you create, and the folder is the index or listing of those Articles (articles/), which is created separately by the Views module. This isn't how it actually functions beneath the surface (files and folders), but should help you understand the structure of the URL path.
After you've created a Content Type (and before you create any content for it), the first stop you should make is Pathauto. In Drupal 6, the settings for Pathauto have been joined into the URL aliases setting page, and are located at Administer > Site building > URL aliases > Automated alias settings (admin/build/path/pathauto). In Drupal 5, Pathauto's settings can be found at Administer > Site configuration > Pathauto
(admin/settings/pathauto).
In case you're wondering why it's best to set up Pathauto "before" making content, it's because the creation of content adds a URL alias to Drupal - if you haven't customized how the alias should be set up, Drupal (or Pathauto if installed) uses the default settings (e.g. Drupal makes node/# and if Pathauto is installed, it instead makes content/page-title). Once an alias is made, it has to be deleted in order for Pathauto to "remake" it the way you prefer.
Note: In case you do have pre-existing URL aliases which were made before installing Pathauto and/or before reading this, then it's simple to clear the old ones out and automatically generate the new customized ones. If you do not have "custom" aliases that you wish to keep (e.g. written by hand), you can simply click on the "Delete aliases" link at the top of the URL aliases page (admin/build/path/delete_bulk). From here you can check the content checkbox and press the "Delete aliases now!" button. Don't worry - in the next step with Pathauto you'll be able to regenerate aliases for every page on the site, according to your exact settings, with the click of a button. If you happen to have hand-written custom URL aliases and can't delete them all like this, consider switching to allow Pathauto to handle all of your paths to make things easier for yourself - if not you can still delete aliases on a case by case basis from the List view of "URL aliases".
articles/[title-raw]
Note: This is where what was explained earlier on this page in "Understanding Drupal Paths" comes into play - the articles/ part of the path here is just a placeholder for the View, making the article both appear and function as if it were "within" the articles/ listing page ("folder"). In this way, the paths will also behave logically the way a site visitor would expect them to (like files inside a folder), allowing them to remove the end of an article's path and arrive at the index/listing of all the articles.
Bulk generate aliases for nodes that are not aliased option.Since Path and Pathauto module create "aliases" to content on your site, the original paths to those pages such as node/2 still exist as well (an alias is just a "mask" of sorts that covers up the original URL with a more friendly one. If you are concerned about possible penalties from search engines due to duplicate content (e.g. two different URLs with the same content) then you should install the Global Redirect module. What it does is ensures that all other URLs that lead to a piece of content get forwarded to your friendly Pathauto URLs.
Breadcrumbs are a valuable and well-understood way to improve navigation on a website. Breadcrumbs allow you to "leave a trail" from the page you are currently on (e.g. an Article), up the structure of your site and back to the home page. You can see an example of them in action on this site even (have a look at the top of the page below the logo).
If your theme has included them (as most do - if not, you should add <?php print $breadcrumb; ?> to your page.tpl.php file), Article content that you create will already show breadcrumbs. However by default they will show only as "Home" (which is not all that helpful). The Custom Breadcrumbs module will allow you to customize this so that a link to the "Articles" listing page will be included: "Home › Articles" (in both cases the Name of the Article is shown below as the page title/heading). The breadcrumbs are not limited to a single level either (if you have a reason to, you could include as many levels of links as you'd like).
Article from the Node type drop down menu.Articles, and in the Paths field, enter articles. Leave the Breadcrumb visibility field empty. Press the "Submit" button to proceed.Now that the Content Type is complete, you should now go ahead and create one or more pages of Article content to use for testing throughout the remainder of this gude (they can just be fake/test pages for now). Go to Create Content > Article, fill in all of the fields, and "Save" the content.
After saving the Article, you'll notice that:
Later in the guide you'll learn how to theme these Article pages to look exactly the way you want them to.