10. Adding a 'more' link and showing all entries
Last modified: January 5, 2008 - 23:05
We now have a function that creates a page with all the content created a week ago. Let's link to it from the block with a "more" link.
Add these lines just before that $block['subject'] line. These lines will add the more link to the end of the $block_content variable before saving it to the $block['content'] variable:
<?php
// add a more link to our page that displays all the links
$block_content .=
"<div class=\"more-link\">".
l(
t("more"),
"onthisdate",
array(
"title" => t("More events on this day.")
)
)."</div>";
?>This will add the more link to the block. Note the extra parameters used in the l() function. You can add additional values, such as 'class', in the array to customize the link.

In which function
This code should be added to the
onthisdate_blockfunction resulting in: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
// content variable that will be returned for display
$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
$limitnum = variable_get("onthisdate_maxdisp", 3);
$query = "SELECT nid, title, created FROM " .
"{node} WHERE created >= %d " .
"AND created <= %d";
$result = db_query_range($query, $start_time, $end_time, 0, $limitnum);
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, return nothing.
return;
}
// add a more link to our page that displays all the links
$block_content .=
"<div class=\"more-link\">".
l(
t("more"),
"onthisdate",
array(
"title" => t("More events on this day.")
)
)."</div>";
// set up the block
$block['subject'] = 'On This Date';
$block['content'] = $block_content;
return $block;
}
}// function onthisdate_block
Correction
(For Drupal 6, at least) the array attributes (title) should be:
<?phparray( "attributes" => array(
"title" => t("More events on this day."))
)
?>
instead of
<?phparray(
"title" => t("More events on this day.")
)
?>
According to the l() documentation at http://api.drupal.org/api/function/l/6