Display a more visibel "Read more" link with Drupal

Drupals “Read more” link is by default displayed together with other links like “Add new comment” at the bottom of the teaser display. Readers not used to blogs and other moderns web sites can easily miss that there is more to read.

Luckily Drupals hook_nodeapi makes its easy to add content to the node display. Here is the function I have just added to this site to display “Read the rest of this posting.” right after the teaser content.

<?php
/**
* Implementation of hook_nodeapi().
*/
function xdeb_addons_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch (
$op) {
    case
'view':
      if (
$teaser && $node->readmore) {
       
//$node->readmore = FALSE;
       
$node->content['xdeb_read_more'] = array(
         
'#value' => '<div class="read-more">'. l(t('Read the rest of this posting.'),
           
"node/$node->nid", NULL, NULL, NULL, TRUE) .'</div>',
         
'#weight' => 10,
        );
      }
      break;
  }
}
?>

Uncomment the line “$node->readmore = FALSE” if you don’t want the default “Read more” link to display.

For most of my sites I have a module where I put the custom functions that don’t belong in the themes template.php. I name this module “[site_name]_addons”, so for this site it’s “xdeb_addons”.

There is a Read More Tweak module that can do this and have a lot of options. It can also fix “read more” links in RSS-feeds. A lot more stuff than I need.

This is for Drupal 5.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.