I want to sort all comment descending programmatically, I found this Comments sorted by oldest first but I dont want use those modules or views solution.
anybody know how can I sort comment descending programmatically?
I means comments in below node(contents) , first ideal is get comments related to node by query and set orderby DESC
but everything show reversed in thread mode, replies come above comment !!!.
-
Comments attached to a node or All comments in the website ?– Anil SagarCommented Mar 1, 2014 at 13:45
-
comments attached to node in view of node– YuseferiCommented Mar 1, 2014 at 13:53
Add a comment
|
1 Answer
<?php
$query = db_select('comment') ->fields('comment', array('cid')) ->condition('nid', arg(1), '=');
$query->orderBy('created', 'DESC');
$result = $query->execute();
$cids = $result->fetchCol();
$comments=comment_load_multiple($cids);
foreach($comments as $comment) {
//do some stuff with the comment
}
?>
-
1but do u think about how they come in thread mode ? replay placed above comment !!! (everything reversed>, tnx for you attention but this is not complete solution.– YuseferiCommented Mar 1, 2014 at 17:08
-
Can you update your question with above details which will help others ? I mean thread mode.. Commented Mar 1, 2014 at 17:15
-