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.

See Also

Comments

tomato-2’s picture

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 :

<?php
 function onthisdate_block($op='list', $delta=0, $edit= array()){
		if ($op = 'list'){
			$block[0]['info'] = t('On this date');
			return $block;
		}elseif ($op = 'view'){
			$block_content = '';
			$today = getdate();
			$start_time = mktime(0,0,0,$today['mon'],$today['mday'],$today['year']);
			$end_time = $start_time+86400;
			$query = "SELECT nid, title,created FROM {node} WHERE created >=  '%d' AND created <='%d'";
			$queryResult = db_query_range($query,$start_time,$end_time);
			while ($links = db_fetch_object($queryResult)){
				$block_content .= l(t($links->title),'node/'.$links->nid).'<br/>';
			}
			
			if ($block_content == ''){
				return;
			}
			
			$option = array('attirbute' => array('title' => t('更多新闻')));
			$link = l(t('更多'),'onthisdate',$option);
			$block_content .= '<div class="more-link">'.$link.'</div>';
			
			$block['subject'] = 'On this Date';
			$block['content'] = $block_content;
			
			return $block;
		}
	}
?>

who can help me? thank you.

jhodgdon’s picture

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.

maartenkuilman’s picture

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.

Nope, thats the current day with the time the day started to the time the day will end.

ibnkhaldun’s picture

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.

tinker’s picture

tomato, You also have errors in conditional statements of your code.

$op = 'list'
// this sets the value of $op to equal 'list'

$op == 'list'
// this compares the value of $op to the value 'list', if they match it returns true

Your code sets the values of $op

        if ($op = 'list'){
            $block[0]['info'] = t('On this date');
            return $block;
        }elseif ($op = 'view'){

It should read

        if ($op == 'list') {
            $block[0]['info'] = t('On this date');
            return $block;
        } elseif ($op == 'view') {
Ilbaboomba’s picture

you also used db_query_range, use instead db_query

animeonx’s picture

    $option = array('attirbute' => array('title' => t('更多新闻')));
//to
    $option = array('attribute' => array('title' => t('更多新闻')));