Community Documentation

Adding a 'more' link and showing all entries

Last updated September 30, 2009. Created by Crisu on January 5, 2008.
Edited by jhodgdon, add1sun. Log in to edit this page.

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

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 :

<?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.

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

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.

________________________________________________________________________

Insanity: doing the same thing over and over again and expecting different results.

RE: I'm confused

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

db_query_range

you also used db_query_range, use instead db_query

<?php    $option =

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

?>

About this page

Drupal version
Drupal 6.x
Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.