• Home
  • About Us
  • Resources
  • Articles
  • Site Update Info
  • Contact
Home
Home

Lesson 2: How to Create Site Update Info module with Main Menu item

PostDateIcon January 25, 2011 | PostAuthorIcon Katy
  • [View]

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.

Bookmark/Search this post with:
PostCategoryIcon Digg Digg  | PostCategoryIcon del.icio.us del.icio.us  | PostCategoryIcon Google Google  | PostCategoryIcon Yahoo Yahoo  | PostCategoryIcon Facebook Facebook  | PostCategoryIcon Twitter Twitter
PostCategoryIcon Printer-friendly version  | PostCategoryIcon Send to friend   | PostTagIcon Tags: Build a module, Drupal Study Group

How to add your new page to Navigation menu

Submitted by Katy on January 26, 2011.

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,
  );
  • reply
Post new comment
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><pre>
  • Lines and paragraphs break automatically.

More information about formatting options

Subscribe by RSS
Syndicate content
Recent blog posts
Lesson 2: How to Create Site Update Info
Jan 25, 2011
Lesson 1: How to Build Your First Drupal
Jan 01, 2011
Drupal Study Group - Learn Custom Module
Jan 01, 2011
My Top 6 Free Themes for Drupal 6 for 2010
Dec 31, 2010
New site upgrade with new Drupal Training
Dec 31, 2010
Recent comments
  • If there are problems with
    Feb 20, 2012
  • GREAT JOB FOR YOU!!! The
    Feb 20, 2012
  • VERY INTERESTING ARTICLE!!!
    Feb 20, 2012
  • Thank you for sharing. radyo
    Feb 18, 2012
  • Thank you for sharing. radyo
    Feb 18, 2012
Popular blog posts
Drupal Advanced Forum vs. phpBB Forum 134,445
How to Convert PSD to Drupal Theme 15,144
Newsletter Subscriptions for Drupal 6 3,607
How to Kill Spam on your Drupal Contact Form 3,577
My Top 5 Drupal Themes 3,409

Copyright © 2009-2011 SeascapeWebDesign.com