Drupal Block Snippet: Zuletzt kommentierte Beiträge

Tagged:  •    •    •    •    •    •  

Drupal 4.7 bietet einen Block, in dem Links zu den neusten Kommentaren angezeigt werden. In dieser Modifikation wird anstelle des Kommentartitles, der Titel des zugehörigen Inhalts angezeigt.

<?php
global $user;
$sql = 'SELECT u.uid, c.name, c.nid, c.subject, c.cid, c.timestamp, n.title
FROM {comments} c
INNER JOIN {node} n ON n.nid = c.nid
INNER JOIN {users} u ON c.uid = u.uid
WHERE n.status = 1 AND c.status = %d ORDER BY c.timestamp DESC';
$result = db_query_range(db_rewrite_sql($sql, 'c'), COMMENT_PUBLISHED, 0, 5);
$items = array();
while ($comment = db_fetch_object($result)) {
  $name = $comment->name;
  if (strlen($name) > 15) {
    $name = substr($name,0,14);
  }
  if ($comment->uid > 0 && user_access('access user profiles', $user)) {
    $author = l($name, 'user/'. $comment->uid);
  } else {
    $author = $name;
  }
  $items[] = l($comment->title, 'node/'. $comment->nid,
  NULL, NULL, 'comment-'. $comment->cid) .' '. t('by') .' '. $author .' '.
  t('%time ago', array('%time' => format_interval(time() - $comment->timestamp)));
  }
return theme('item_list', $items);
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br>

More information about formatting options