El núcleo del problema es este:
$comments = $commentClass->fetch_article_comments($article_id);
Supongo que esta función en algún lugar crea y ejecuta SQL, que es similar a SELECT ... WHERE comments.article_id=$article_id
. Esto no es suficiente, necesita algo como
$comments = $commentClass->fetch_article_comments($article_id, $parent_id);
que se traduce en SQL similar a SELECT ... WHERE comments.article_id=$article_id AND comments.comment_parent ($parent_id>0)?"=$parent_id":"IS NULL"
Ahora puedes escribir tu función PHP:
function display_comments ($article_id, $parent_id=0, $level=0) {
$comments = $commentClass->fetch_article_comments($article_id, $parent_id);
foreach($comments as $comment) {
$comment_id = $comment['comment_id'];
$member_id = $comment['member_id'];
$comment_text = $comment['comment_text'];
$comment_timestamp = timeAgo($comment['comment_timestamp']); //get time ago
//render comment using above variables
//Use $level to render the intendation level
//Recurse
display_comments ($article_id, $comment_id, $level+1);
}
}
Y finalmente llámalo con display_comments ($article_id);