Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+10 votes
2.0k views
in Q2A Core by
can you please add most popular questions tab? may be based on max number of answers to the question. is it easy to implement this feature?

Do you think it will add value?

3 Answers

+1 vote
by
edited by
[This is no longer valid in version 1.2 beta - see later answer.]

There are lots of different ways of slicing and dicing the question list, including by the number of answers that you suggest. Many of these options are planned for future versions, but if you want to sort by the number of answers now, you could also implement it fairly easily, if you're comfortable with a little PHP programming.

First, add something like this to qa-db-selects.php:

    function qa_db_most_answered_qs_selectspec($voteuserid, $start, $hidden=false, $count=QA_DB_RETRIEVE_QS_AS)
    {
        $selectspec=qa_db_posts_basic_selectspec(true);
       
        $selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE type=$ ORDER BY ^posts.acount DESC LIMIT #,#) y ON ^posts.postid=y.postid";
        $selectspec['arguments']=array($voteuserid, $hidden ? 'Q_HIDDEN' : 'Q', $start, $count);
        $selectspec['sortdesc']='acount';
       
        return $selectspec;
    }

Second, add a case to the big switch in qa-page-hone.php by copying the 'unanswered' case, replacing qa_db_unanswered_qs_selectspec(...) with qa_db_most_answered_qs_selectspec(...), and changing other things as appropriate. You can change 'unanswered' to 'most-answers'.

Third, add a rule in the $qa_routing array in qa-index.php that maps the request 'most-answers' to QA_INCLUDE_DIR.'qa-page-home.php'

Last, add a navigation item in the big array in qa_content_prepare() in qa-index.php, again, modeled on the 'unanswered' item.

There's already an index in the database that is suitable for sorting questions by most answers, so it should be a scalable request.
by
will try this, many thanks!
by
I tried to follow you steps but I have problems with this modifications:
Third, add a rule in the $qa_routing array in qa-index.php that maps the request 'most-answers' to QA_INCLUDE_DIR.'qa-page-home.php'

Last, add a navigation item in the big array in qa_content_prepare() in qa-index.php, again, modeled on the 'unanswered' item.

 $qa_routing array in qa-index.php ? I couldn't find that anywhere
qa_content_prepare in qa-index.php ? also not found

I'm using beta version of Q&A
by
Lucifix, a few things have changed in version 1.2 beta, so I'll post a new answer which is compatible with that.
+1 vote
by
[This is an updated answer which should be valid for version 1.2/beta]

First, add something like this to qa-db-selects.php:

    function qa_db_most_answered_qs_selectspec($voteuserid, $start, $count=QA_DB_RETRIEVE_QS_AS)
    {
        $selectspec=qa_db_posts_basic_selectspec($voteuserid);
       
        $selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE type='Q' ORDER BY ^posts.acount DESC LIMIT #,#) y ON ^posts.postid=y.postid";

        array_push($selectspec['arguments'], $start, $count);

        $selectspec['sortdesc']='acount';
       
        return $selectspec;
    }

Second, add a case to the big switch in qa-page-home.php as follows:

case 'most-answers':           
    if (!qa_home_load_ifcategory(
        'page_size_qs', 'feed_for_most_answers', 'cache_qcount', 'main/most_answered_qs_title', 'main/no_questions_found', 'main/most_answered_qs_title', 'main/no_questions_found',
        qa_db_most_answered_qs_selectspec($qa_login_userid, $qa_start)
    ))
        return;
    break;

Third, add the appropriate phrase with the key 'most_answered_qs_title' to the file qa-lang-main.php.

Fourth, add a rule in the $qa_routing array in qa-page.php that maps the request 'most-answers' to: QA_INCLUDE_DIR.'qa-page-home.php'

Last, use the 'Pages' feature of the 'Admin' panel to 'Add a Link' (not 'Add a page'), and set the 'URL of link' to 'most-answers' (without the quotes).

There's already an index in the database that is suitable for sorting questions by most answers, so this should be a scalable request.
by
Thank this is working, but on what conditions are popular questions sorted?
by
I guess, it is based on "no of answers".
by
Gidgreen, is there a way to build this popular questions feature so, that it is based on answers count AND comments count ???

The most active questions ahouldnĀ“t be based on answers only, as the discussions often take place in the comments section only ?

Thank You so far !
by
It's not easy at the moment, because the database doesn't have columns which contain the number of comments, nor the total of As+Cs.
by
Ok, I understand this, but the "most active questions" or "most poular questions" feature only makes sence if comments are counted as well, You can see it here on this question, 2 answers only but 8 comments.
So I would think that this feature including one or two columns for the comment and answers count would be a great additon for the road map.

Regards
monk333
+1 vote
by
Here you find a free widget that displays the most popular (most viewed) questions: http://www.question2answer.org/qa/50490/new-free-plugin-popular-questions-widget
...