Write the Drupal Module
Let say the module name is xxx.
Telling Drupal about your module
Edit modules/xxx/xxx.info:
name = Module Name
core = "6.x"
description = A description of what your module does.
dependencies = module1 module2 module3
version = "1.0"
Telling Drupal who can use your module
Edit modules/xxx/xxx.module:
<?php
/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/
function xxx_perm() {
return array('access content');
} // function xxx_perm()
?>
Declare we have block content
<?php
/**
* Generate HTML for the onthisdate block
* @param op the operation from the URL
* @param delta offset
* @returns block HTML
*/
function xxx_block($op='list', $delta=0) {
// listing of blocks, such as on the admin/block page
if ($op == "list") {
$block[0]["info"] = t(’Block Name 1′);
$block[1]["info"] = t(’Block Name 2′);
return $block;
}
// out block content
else if ($op == ‘view’) {
switch ($delta) {
case 0:
return xxx_block_block1();
case 1:
return xxx_block_block2();
}
}
} // end xxx_block
?>
Generate the block content
function xxx_block_block1() {
$block_content = '';
$query = "SELECT nid, title, created FROM {node} WHERE ...";
// get the links
$queryResult = db_query($query);
while ($links = db_fetch_object($queryResult)) {
$block_content .= l($links->title, 'node/'.$links->nid) . '
‘;
}
// check to see if there was any content before setting up the block
if ($block_content == ”) {
// no content from a week ago, return nothing.
return;
}
// set up the block
$block['subject'] = ‘Block Title’;
$block['content'] = ‘$block_content;
} // end xxx_block_block1
Declare we have new page
<?php
function onthisdate_menu() {
$items = array();
// add a new page
$items[] = array(
‘path’ => ‘xxx’,
‘title’ => t(’…’),
‘callback’ => ‘xxx’,
‘access’ => user_access(’access content’),
‘type’ => MENU_CALLBACK
);
return $items;
}
?>
Generate the page content
<?php
function xxx() {
// content variable that will be returned for display
$page_content = '';
$query = "SELECT nid, title, created FROM {node} WHERE ...";
// get the links
$queryResult = db_query($query);
while ($links = db_fetch_object($queryResult)) {
$page_content .= l($links->title, 'node/'.$links->nid).'
‘;
}
// check to see if there was any content before setting up the block
if ($page_content == ”) {
// no content, let the user know
$page_content = “No events occurred on this site on this date in history.”;
}
print theme(”page”, $page_content);
}
?>
Create new node type
function xxx_node_info() {
return array (
'xxx' => array(
'name' = > t('Node Name'),
'module' => 'xxx',
'description' => t("Create content description"),
)
);
}