Creating a simple Drupal 6 blog using CCK and Views - Pt1.

July 15
blog author



When I first started with Drupal, the exercise that helped me the most to understand how Drupal works was to create a simple blog. Now, back then, there were a lot of tutorials on how to do it using the blog module (which is great) but this is a learning experience so I’ll show you how I did it using CCK and Views.

First of all we’re going to download and enable a couple of modules we’ll need to get this done (If you’re somewhat familiar with Drupal I recommend using Drush for this).

  • CCK
  • CCK - File Field (If you’re palling to add a image field)
  • CCK - Imagefield (If you’re palling to add a image field)
  • Views
  • ImageAPI (If you’re palling to add a image field)
  • Imagecache (If you’re palling to add a image field)
  • Token
  • Pathauto

Then we’ll..

Create the new blog content type:

  1. Go to administer -> Content Types -> Add Content Type (admin/content/types/add).
  2. Set the name, type, and description. I’m using: name: blog entry, type: blog.
  3. Edit the “workflow settings”. Personally I don’t like to have my content published to the front page by default so I always uncheck this.
  4. Set the comment settings to your preference.


Create the content fields:

Any new content types you create will have a title and a body by default, so more then half of the work is done for you already. If you decide to add an image field here is what you’ll have to do:

  1. Go to “Manage Fields”
  2. Scroll to the bottom when you’ll see an “Add” row and complete the fields with the information for the new field.
    • Label: Blog Image
    • Field: blog_image
    • Type: file
    • Widget: image.
  3. Hit save and complete the settings to this field to your preference (file restrictions, etc)


Create the imagecache presets for the image and apply them (optional).

Nobody likes to have upload images that are already scale and cropped to the perfect size, so we’ll let imagecache handle that.

  1. Go to: site building -> imagecache -> add (admin/build/imagecache/add) and create a new preset.
  2. Select whichever actions you want to add to the image (scale, crop, etc) and save it.
  3. Go back to your content types (admin/content/types) and select manage fields for the blog content type.
  4. Click the “Display Fields” tab on top and apply the preset to the image on the teaser and node pages. Typically the teaser would be “preset_name linked to node” and node “preset_name image”.
  5. Save


Create a blog listing page using views:

Now that the content type is ready you’re missing a page that will list the latest blog posts. Thats when views comes in place.

  1. Go to: site building -> views -> add (admin/build/views/add) and create a view named “blog”. We’ll be using the default node view type.
  2. Under Basic Settings:
    • Set "Name" to: Blog
    • Set "Title" to whichever title you want for the blog listing page.
    • Set "Row Style" to node (Default options are ok and you can change this later).
    • Set "Use Pager" to yes and which type of pager you want to use.
  3. Under Sort Criteria:
    • Click the plus sign.
    • Select “Node Published” click add.
    • Select descending so newer posts get displayed first.
  4. Under Filters:
    • Click the plus sign.
    • Select Node Type and click add
    • Select: it’s one off and blog entry. Click update.
    • Click the plus sign again and select Node Published
    • Select yes (we’re making sure that only nodes that are published get displayed)
  5. Create a Page Display
    • Look on the left side for a select element that is right under “defaults”, select page click add display.
    • Go to the page settings and set the path to blog
  6. Save the view

At this point if you go to /blog you’ll see an empty page but if you go ahead and create some posts you’ll see the listing growing.

Now there is just one last step to it.

Set the path of the blog nodes.

Typically you would want to set the path to your blog posts to “blog/blog-title” to keep it user friendly and aid you when placing blocks that are dedicated to the blog section of the site. To do that you ‘ll have to:

  1. Go to: site building -> url aliases ->automated alias settings (admin/build/path/pathauto)
  2. Open the “Node Paths” settings an set the blog paths to blog/[title-raw]

And thats it! You finished building your blog.

Now on the next post I’ll talk about adding tags to your blog and creating an RSS feed also using views.


Erico Vinicius