I know how to create a simple list of comments, such as here. http://drupal.org/node/56235

However, this shows ALL comments, even if they are attached to unpublished nodes. Can someone alter this code to only list comments on published nodes?

thanks

$max = 10;
$query = 'SELECT nid,cid,subject FROM {comments} order by timestamp desc ';
$result = db_query_range($query, 0, $max);
$items = array ();
while ($comment = db_fetch_object($result)) {
    $items[] = l($comment->subject, "node/$comment->nid", NULL, NULL, "comment-$comment->cid");
}
if (count($items)) {
    return theme('item_list', $items);
}

art

Comments

nevets’s picture

Change the query to

$query = 'SELECT c.nid,c.cid,c.subject FROM {comments} c JOIN {node} n USING(nid) WHERE n.status = 1 order by timestamp desc ';