Adding a 'more' link and showing all entries

Last modified: September 30, 2009 - 20:12

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:

<?php
// 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

I'm confused

tomato - May 7, 2009 - 07:34

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.

花谢花飞花满天,红綃香断有谁怜

Bad time frame.

jhodgdon - May 19, 2009 - 22:54

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.

RE: I'm confused

tinker - November 3, 2009 - 23:47

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') {

 
 

Drupal is a registered trademark of Dries Buytaert.