01. Getting started

To focus this tutorial, we'll start by creating a block module that lists links to content such as blog entries or forum discussions that were created one week ago. The full tutorial will teach us how to create block content, write links, and retrieve information from Drupal nodes.

Start your module by creating a folder in your Drupal installation at the path: sites/all/modules/onthisdate You may need to create the sites/all/modules directory first. Create a PHP file and save it as onthisdate.module in the directory sites/all/modules/onthisdate. As of Drupal 5.x, sites/all/modules is the preferred place for non-core modules (and sites/all/themes for non-core themes), since this places all site-specific files in the sites directory. This allows you to more easily update the core files and modules without erasing your customizations.

<?php
// $Id$

As per the Coding standards, omit the closing ?> tag and use the longhand <?php tag. (Note that the examples in the handbook will show the closing tag for formatting reasons only and you should not include it in your real code.) The $Id$ string will help keep track of the revision number and date when you commit the file to CVS.

All functions in your module that will be used by Drupal are named {modulename}_{hook}, where "hook" is a pre-defined function name suffix. Drupal will call these functions to get specific data, so having these well-defined names means Drupal knows where to look. We will come to hooks in a while.

The module is not operational yet: it hasn't been activated. We'll activate the module later in the tutorial.

 
 

Drupal is a registered trademark of Dries Buytaert.