Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
673 views
in Q2A Core by
edited by
I can see many requests for this feature. Due to the lack of this feature many answers are not getting deserved views when sorted by votes. Or when sorted by Time, most voted answers are getting the chances missed.

Was wondering until the feature gets developed , would this be a temporary solution :

There is a way in the admin panel to set sorting style (Votes/Time). Is it possible to hack into the core and whereever we have that if block which decides this logic, can we have a random function like for eg: rand (0,1) and leave that to decide ?

This would actually help a lot in my case. because both high voted answers and recent answers will get equall chances to get views ?

File: question.php

look for the line :    if (qa_opt('sort_answers_by')=='votes')

and replace it with : if(rand(0,1)==0)

is this something doable and safe?
Q2A version: 1.7.4
by
btw. looks like time sorting is coded to be Ascending. This needs to changed to DESC in order for the idea to work too.

1 Answer

+1 vote
by

Managed to sort this as i wanted. Not sure if this is helpful for anyone but, it did help me acheive my requirement. 

My requirement was originally to have an option to sort answers by highest votes at top and most recent comments at top.

However, as this feature doesnt exist yet. I managed to get the following done :

 1. Everytime a question page is opened. it will randomly decide option A or B and renders results accordingly.

 2. This helps me in 2 ways. 50% of the page views will see highest voted answers at the top. while another 50% will get to see most recent answer added at the top. Thereby promoting every post equally. 

Did the following :  

File: question.php

look for the line :    

        if (qa_opt('sort_answers_by')=='votes') 


and replace it with : 

        if(random_int(0,1)==0)

Also, since i wanted a reverse ordering with most recent post at the top, i had to add a 3rd line too (in the else part of the if block:)

      $answers=array_reverse($answers);

I am sure there might be a few performance issues around this however. does the job for me.

...