Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to show recent answers on top? Thanks for your help.

+3 votes
179 views
asked May 9 in Q2A Core by john123
Currently q2a shows new answers on bottom. How can i show new answers on top instead?

There is a discussion but i could not find any solution.

http://www.question2answer.org/qa/14953/question-view-page-showing-recent-answers-first-answers-last?show=14953#q14953

Thanks for your help.
Q2A version: Latest

1 Answer

+2 votes
answered May 10 by sama55

Probably, this is an answer.

qa-include/pages/question.php (In case of V1.7.4,  L283-L290)

Before:

if (qa_opt('sort_answers_by')=='votes') {
    foreach ($answers as $answerid => $answer)
        $answers[$answerid]['sortvotes']=$answer['downvotes']-$answer['upvotes'];

    qa_sort_by($answers, 'sortvotes', 'created');

} else
    qa_sort_by($answers, 'created');

After:

if (qa_opt('sort_answers_by')=='votes') {
    foreach ($answers as $answerid => $answer)
        $answers[$answerid]['sortvotes']=$answer['downvotes']-$answer['upvotes'];

    qa_sort_by($answers, 'sortvotes', 'created');

} else {
    qa_sort_by($answers, 'created');
    $answers = array_reverse($answers, true);
}

Note: 

  • There is no solution other than core hacking.
  • This is a partial (not fundamental) solution.
commented May 11 by john123
@sama55,

Thank you for the code. I tried this solution but it does not filter recent answers on top.

I think it could be simple solution, just to reverse the order of answers, from top to bottom and bottom to top. I wish we had that option.
commented May 11 by sama55
I confirmed that the code above works correctly. Are your options below correct?
"Admin" > "Viewing" >"Sort answers by" <=== You should set 'Time'.
"Admin" > "Viewing" >"Move selected answer to the top" <=== In case of ON, selected answer is placed on the top.
commented May 12 by john123
I agree @sama55. Your updated code works perfectly.  Thank you for clarifying it.
...