Fresh Blurbs

How to Hack 'Read More' in Drupal

As you know Drupal displays the "Read more" link among all other after-teaser links in the blog postings view. This is not a usual user-experience. Most users expect "read more" link to be right after the teaser part of the posting. It can get confusing, so following is a quick-n-dirty hack that can fix it for you:

Locate the piece of code in node.tpl.php where it reads like:

 <?php print $content ?>

Put the following right after it:

<?php
// Extract "read more" link from $links so we can display it separately.
if (preg_match('!<a[^>]+>'.t('Read more').'</a>!', $links, $match)) {
  $links = preg_replace('/<a.+?href.+?>'.t('Read more').'<\/a>/i', '', $links);
  $more = '<div align="right">'. $match[0] . '</div>';
  $more = str_replace ("Read more", "Read the rest of the posting...", $more);
}
else {
  $more = '<span class="readmore-fill"></span>';
}

if ($more) { print $more; }

?>
comments powered by Disqus