In this tutorial, we will create a single page that displays information on when the site was updated. We will also add a menu item to the Main Menu called Site Update Info.
I recently updated a client’s site from Drupal 6.17 to 6.20. I wanted to keep track of the dates that I had performed site updates. I created a site.txt file and saved it in the root folder. The text file looks like this:
/* Site Update info */ Updated Jan 22, 2011 from Drupal 6.17 to 6.20 using Acquia Drupal 1.2.33 by Katy of SeascapeWebDesign.com Updated Aug 10, 2010 from Drupal 6.13 to 6.17 using Acquia Drupal 1.2.26 by Katy of SeascapeWebDesign.com Launched Aug 2009 Drupal 6.13 using Acquia Drupal 1.2.12 by Katy of SeascapeWebDesign.com
Then I thought I would like to make a module to display this info on a page within the site. Then this info would be easier to access.
So let’s create a simple module that creates one page of text and adds a single item to the Main Menu.
1. First let’s start with our Hello World module that you coded in Lesson 1: Build Your First Drupal Module.
We only need to add one line of code to add the page to the Main Menu which is also called Primary Links. Be sure to have Primary links enabled on your Drupal site.
Add this line to the hook_menu function.
'menu_name' => 'primary-links',
So the result looks like this:
/**
* Implementation of hook_menu()
*
*/
function hello_world_menu() {
$items = array();
$items['hello_world'] = array(
'title' => 'Hello World',
'page callback' => 'hello_world_page',
'access arguments' => array('access content'),
'menu_name' => 'primary-links',
);
return $items;
}
So now you will see the new menu item "Hello World" appear in the Main Menu.
So that was easy!
2. Now let’s create a new module that displays your Site Update info and creates a menu item.
Copy the folder hello_world and rename it siteupdated.
Rename the .info file to siteupdated.info
Rename the .module file to siteupdated.module
In these 2 files, rename every instance of hello_world to siteupdated
So the .info file looks like this:
; $Id: siteupdated.info $ name = Site Update Info description = "This module creates menu item and displays 'Site Update Info' page" core = 6.x version = "6.x-dev"
and the siteupdated.module looks like this:
<?php // ; $Id: siteupdated.info $ /** *@file siteupdated.module * * The siteupdated module creates menu item for Site Update Info page */ /** * Implementation of hook_menu() * */
function siteupdated_menu() {
$items = array();
$items['siteupdated'] = array(
'title' => 'Site Update Info',
'page callback' => 'siteupdated_page',
'access arguments' => array('access content'),
'menu_name' => 'primary-links',
);
return $items;
}/**
* Generate page of text
*/
function siteupdated_page() {
$mysiteinfo = '<p>Upgraded Jan. 1, 2011<br /> from Drupal 5.23 to 6.20</p>
<p>Updated site Dec. 31, 2011<br /> from Drupal 5.7 to 5.23<br /> by Katy</p>
<p>Launched July 2008<br /> Drupal 5.6 <br />by Katy</p>';
return $mysiteinfo;
}
3. Click on the menu item above on this site, "Site Update Info" to see this module in action.
4. Create your own page of text to display on your Drupal site.
If you want your text to be translatable, then use this code:
function modulename_page() {
return '<p>' . t(The quick brown fox jumps over the lazy dog.') . '</p>';
}
5. Your Homework Assignment:
Download the examples module and investigate page_example.module
You can also investigate menu_example.module
6. Post your questions and comments here. Describe the module that you created and send a link to show us.
Copyright © 2009-2011 SeascapeWebDesign.com

How to add your new page to Navigation menu
Use this code for hook_menu function and it will add your new page to Drupal's Navigation menu. Try it out for yourself:
function siteupdated_menu() { // This is the minimum information you can provide for a menu item. // This menu item will be created in the default menu (Navigation). $items['siteupdated'] = array( 'title' => 'Site Update Info', 'page callback' => 'siteupdated_page', 'access callback' => TRUE, 'expanded' => TRUE, );