Closed (won't fix)
Project:
Node Comments
Version:
6.x-2.0-beta6
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Jan 2011 at 23:56 UTC
Updated:
8 Sep 2011 at 10:15 UTC
I have a list of recent comments, and links with trimmed versions of the comment content pointing to the comment location within a node. Currently I'm using this very awkward piece of code to make it happen:
function recent_comments($filter_query, $chars = 30, $limit = 5) {
$sql = db_query("SELECT nc.nid nid, nc.cid cid, nc.name name, nc.uid uid, node.created created, node.title title, if(n.type = 'forum', 1, 0) is_forum FROM node_comments nc, node node, (SELECT type, nid FROM node) n WHERE nc.cid = node.nid AND node.type = 'comment' AND n.nid = nc.nid AND status = '1' AND " . $filter_query . " ORDER BY node.created DESC LIMIT %d", $limit);
while ($n = db_fetch_object($sql)) {
$path = drupal_get_path_alias('node/' . $n->nid);
$node_comment = node_load($n->cid);
//trim the body to make it presentable within the allocated space
$node_comment->body = trim_string($node_comment->body,100);
if ($n->uid != 0) {
$userlink = l($n->name, 'user/' . $n->uid);
}
elseif ($n->name) {
$userlink = $n->name;
}
else {
$userlink = 'Anonymous';
}
if ($n->is_forum) {
$locator = '#comment-';
}
else {
$locator = '#node-';
}
$items .= '<div class="comment-unit">' . l('"' . $node_comment->body . '"', url($path, array('absolute'=>TRUE, 'attributes'=>array('node_comment_list'))) . $locator . $n->cid, array('attributes'=>array('class'=>'link_underline'))) . '<br />by ' . $userlink . ',<br />' . t('@time ago', array('@time' => format_interval(time() - $node_comment->created, 1))) . '</div>';
}
print '<div class="comment-list">' . $items . '</div>';
}
I wanted to use views but couldn't get it to work (when I do ask how it can be done, I usually get the very unhelpful answer; "Just use views!"), and so far it's worked fine. However, I've since enable pagination and this has broken the code for comments not on the first page of a forum topic. Any ideas how to make it work?
Comments
Comment #1
crea commentedDo you seriously expect people to read and fix your code ? Please don't abuse support issue queue.