Generating page content
Main topic described: Displaying content
So far we have our working block and a settings page. The block displays a maximum number of links. However, there may be more links than the maximum we show. So, let's create a page that lists all the content that was created a week ago. This is a three-step process, which we'll describe on this tutorial page and the next two pages.
The first step, described on this page, is to add a new function to our onthisdate.module file that will output a complete list of all the content that was created a week ago. We'll name this function onthisdate_all() (we could choose another name, but it must start with "onthisdate_").
A quick note on function naming conventions in Drupal: If you are creating a function that you intend to be strictly private (i.e. no other module should rely on it being a stable function or call it), start the function name with "_your_module_name_". If your function is public (i.e. it would be OK for another module to call it, and you don't intend to change its argument signature or behavior often), start the function name with "your_module_name_". If you are implementing a Drupal hook, you must always name the function "your_module_name_hookname".
So, back to the new onthisdate_all() function in the onthisdate.module file. It is basically going to reproduce the original version of our block, from before we put in the option to limit the block to a certain number of links (see page 5 of the tutorial), and we want the function to return the HTML content for the page. Note that we don't have to worry about HTML headers, page titles, menus, footers, etc. We only have to generate the content section of the page, and Drupal and our theme will take care of the rest. Here's the part of the function that is essentially copied from the block function:
<?php
function onthisdate_all() {
// content variable that will be returned for display
$page_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
$query = "SELECT nid, title, created FROM " .
"{node} WHERE created >= '%d' " .
" AND created <= '%d'";
// get the links (no range limit here)
$queryResult = db_query($query, $start_time, $end_time);
while ($links = db_fetch_object($queryResult)) {
$page_content .= l($links->title, 'node/'.$links->nid) . '<br />';
}
// More coming....
}
?>As noted before, we're including layout in the code. This is bad, and should be avoided. It is, however, the topic of another tutorial, so for now, we'll include the formatting in our content.
Also note that, as in the case of a block, you might want to incorporate a different time range if your site has no content on that particular date one week ago.
The rest of our function checks to see if there is content and lets the user know. This is preferable to showing an empty or blank page, which may confuse the user.
<?php
function onthisdate_all() {
// Be sure to include the previous piece of this function!
// check to see if there was any content before
// returning the page
if ($page_content == '') {
// no content from a week ago, let the user know
$page_content = "No events occurred on this site on this date in history.";
}
return $page_content;
}
?>Even though we have this function that will output links to the content generated a week ago, we haven't specified what URL will display this page. We'll do that next.

Next Page Link?
Is there a next page to this tutorial? The next link goes to a page on how to embed cck fields into a page, but the article flow expected to see a page about how to put a menu link to the page function just created. Is this still in progress?
Fallow The Next
Fallow The Next http://drupal.org/node/206764