How to create a drupal blog in 10min

8/17/10

Overview

In this tutorial, we will show you how to build a blog and an RSS feed of that blog in Drupal using Views. Views is a query builder which allows you to display content based on multiple criteria.

Pre-requisite modules

Before we start, we need to install Views which can be found at http://drupal.org/project/views.

Building the Blog content type

First off, we need to create the content type, which will store the blog title and body. You can create a new content type by going to the administrator page, under Content Management, Content Types. Here are a few steps on how to do so:

  1. Click on the Create Content Type tab
  2. Name is the Human readable content type title; call it “Blog”, or “Blog entry”. Type is the machine readable name; call it blog, or blog_entry.
  3. Save

Making Dummy content

Because Views shows a live preview of the result, we want to add a couple of sample blog articles. You can do so by going to node/add and selecting “Blog Entry”. Add three or four dummy blog entries.

Creating the view

You can access Views by going logging in as an administrator and going to: admin/build/views/

Add a new view by clicking on the “Add” Tab. The View Name needs to be a machine readable name (no spaces and no special characters); call it “blog”. Write a simple description of the view and click Next.

Next, you will be presented with the default blank view. Views can have different Displays and all the displays inherit from the Default Display. A Display can be of type Block, Page or Feed. We will start from Fields.

Fields

Fields are what is going to be displayed. In our case we want to display our Title, Teaser body and a link to read more.

  1. Click on the + symbol.
  2. Select Node: Title, Node: Body and Node: Link.
  3. For Node: Body:
  4. Leave the “label” field blank (we don’t want this to show up).
  5. Select “Trim this field to a maximum length” and under Maximum Length enter 2000. This will act as our “teaser”.
  6. Trim this field to a maximum length
  7. Click Update.
  8. For Node: Link:
  9. Leave the “label” field blank (we don’t want this to show up).
  10. Under “Text to display”, write: “read more” (this will be the link text).
  11. For Node: Title
  12. Leave the “label” field blank (we don’t want this to show up).
  13. Select “Link this field to its node”, this way, the title will output as a link to the article.
  14. Reorder the fields so they are in the following order. You can do so by clicking on the arrows symbol.

Filters

By now, you can see in the Live Preview, that all of your content is showing up, not only blog articles. This is where Filters come in handy. Filters are if statements, which filter the result of the view. In SQL terms, they are WHERE clauses. Because you can have multiple content types, we will use a filter to display only blog articles.

  1. Add a filter by clicking on the + icon
  2. You will be presented with a list of fields; select Node: Type and click Add.
  3. Select which content types to display. In this case select “Blog Entry”, or whatever you named you content type.
  4. Click Update

Good practice is also to filter content that is published. You can do so by adding a new filter (Node: Published) and set it to “Yes”.

Sorting

Now we have a list of articles but they are sorted incorrectly because we want to show the latest article at the top, not the bottom. We will add a new field to do so.

  1. Add a new field, like before, click on the + symbol.
  2. Select Node: Post Date
  3. Select Descending
  4. Click on Update

By now, you should be more familiar with the interface so we will skip some of the steps. From the Basic Settings pane, we can adjust a lot of the settings. First of all, let’s add a pager to this view. Click on Use Pager: No, and change it to Full Pager.

The view is now completed so let’s save it by clicking on the Save button on the bottom.

Creating the two displays (latest articles and RSS feed)

Latest articles

We now have our view created so how do we create the actual page? We can do so by creating a new Page Display and assigning it to a path. On the right sidebar, select Page, and Add Display. You will notice that all fields are in italics. That means that they are inheriting from the Default Display. Under the Path Settings pane, click on Path: None and write the URL where this blog will be displayed. In our case we will write “blog”. Save the View.

You can now access you blog at http://www.yoursite.com/blog

RSS Feed

Creating an RSS feed is very simple. Follow the same steps but instead of selecting Page as you display type, you would select Feed and in the path settings you would write “blog/rss”.

Save the View and you can now access your RSS feed at http://www.yoursite.com/blog/rss