Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 in function onthisdate_block()
. These lines will add the more link to the end of the $block_content variable before returning it to the block module:
// add a more link to our page that displays all the links
$options = array( "attributes" => array("title" => t("More events on this day.") ) );
$link = l( t("more"), "onthisdate", $options );
$block_content .= "<div class=\"more-link\">" . $link . "</div>";
This will add the more link to the block. Note the extra parameters used in the l() function. You can add additional elements, such as 'class', in the array to customize the link.
Comments
I'm confused
I placed the onthisdate block at left sidebar ,and I can see the content page ,but why the onthisdate block doesn't display.My onthisdate_block function code :
who can help me? thank you.
Bad time frame.
The block is set to completely not display if there is no content on that particular date.
You have set the time frame to
$start_time = mktime(0,0,0,$today['mon'],$today['mday'],$today['year']);
$end_time = $start_time+86400;
i.e. your start time is now, and your end time is in the future.
I don't think you'll get any content displayed.
Time
Nope, thats the current day with the time the day started to the time the day will end.
Set your selection to enought days
Perhaps you have no documents to show.
use:
$start_time = mktime(0,0,0,$today['mon'],($today['mday']-7),$today['year']);
$end_time = $start_time+(8 * 86400);
change the query string adding an ORDER BY clause
$query = "SELECT nid, title, created FROM " .
"{node} WHERE created >= '%d' " .
" AND created <= '%d' ORDER BY created DESC";
This variation creates a simple "New on this site" option
Add a couple of dummie pages to your site to ensure you have what to see.
Also verify your conditional sentences.
RE: I'm confused
tomato, You also have errors in conditional statements of your code.
Your code sets the values of $op
It should read
db_query_range
you also used db_query_range, use instead db_query
<?php $option =