I have a need to determine if comments have replies. This is what I've come up with to make this determination, but I would rather find a way that doesn't require an additional database query per comment.
function theme_preprocess_comment(&$variables) { $comment = $variables['elements']['#comment']; $count = db_query('SELECT COUNT(*) FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid))->fetchField(); $comment->has_children = !empty($count); }
I can see that theme_preprocess_node has access to the entire array of comments in its $variables argument when displaying it with print_r. The issue is I can't seem to figure out how to loop over the comments so that I could check for a value in the pid field and add a has_children => TRUE to the parent comment's array.
Can someone point me in the right direction?
Thanks, cameronbprince