hack

Drupal: Latest Comments Block in User Profile.

In Drupal 5, if you want the User Profile page (e.g. http://example.com/user/stevejobs) to display latest comments by that user, you can apply a quick hack:

  1. Create or edit user.profile.tpl.php file in your theme
  2. Add the following code anywhere (wherever you want latest comments to appear) in the file:
    <?php
    $output = ""; $nlimit = 7;
    $userid=$user->uid;

    // ATTENTION: status=0 - approved, status=1 in queue.
    $query= "SELECT c.cid, c.nid, c.name, c.subject
    FROM {comments} c WHERE c.uid = %d AND c.status = 0
    ORDER BY c.timestamp DESC";

    $result = db_query_range($query,$userid,0,$nlimit);
    $output .= "<div class=\"item-list\"><ul>\n";

    $no_comments = mysql_affected_rows ();

    if ( $no_comments > 0 ) {


    while ($obj = db_fetch_object($result)) {
    $link = url("node/$obj->nid");
    $link = $link."#comment-".$obj->cid;
    $output .= "<li><a href=\"$link\">$obj->subject</a></li>";
    }

    } else {
    $output .= 'No Comments left so far.';
    }

    $output .= "</ul></div>";
    print $output;
    ?>

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; }

?>
Syndicate content