มอดูลนี้ เราจะสร้างรายการของเนื้อหา (nodes) ของวันนี้ในสัปดาห์ก่อน เวลาเราจะดึงรายการมา เราดูจากเวลาที่เนื้อหาถูกสร้าง โดยเราทำในรูปวินาที (ดู php เรื่องเวลา)
<?php
/**
* Generate HTML for the onthisdate block
* @param op the operation from the URL
* @param delta offset
* @returns block HTML
*/
function onthisdate_block($op='list', $delta=0) {
// listing of blocks, such as on the admin/block page
if ($op == "list") {
$block[0]["info"] = t('On This Date');
return $block;
} else if ($op == 'view') {
// our block content
// Get today's date
$today = getdate();
// calculate midnight one week ago
$start_time = mktime(0, 0, 0,
$today['mon'], ($today['mday'] - 7), $today['year']);
// we want items that occur only on the day in question, so
// calculate 1 day
$end_time = $start_time + 86400;
// 60 * 60 * 24 = 86400 seconds in a day
}
//We'll use db_query() to get the records (i.e. the database rows) with our SQL query
$result = db_query("SELECT nid, title, created FROM {node} WHERE created >= '%s' AND created <= '%s'", $start_time, $end_time);
// content variable that will be returned for display
$block_content = '';
while ($links = db_fetch_object($result)) {
$block_content .= l($links->title, 'node/'. $links->nid) .'<br />';
}
// check to see if there was any content before setting up
// the block
if ($block_content == '') {
/* No content from a week ago. If we return nothing, the block
* doesn't show, which is what we want. */
return;
}
// set up the block
$block['subject'] = 'On This Date';
$block['content'] = $block_content;
return $block;
}
?>db_query() โดยให้ชื่อตารางในฐานข้อมูลอยู่ในรูป {node} ดูรายละเอียดจาก Table Prefix (and sharing tables across instances)db_fetch_object()l() ให้อยู่ในรูปของ <li><a href="node/nid">title</li>