Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
412 views
in Q2A Core by
Hi,

I've been using Q2A for a while and is really impressed by the API. I designed a plugin as well as an Advanced theme, to add some custom features.

I need to show a List of Questions on the Custom Page I designed as a part of my plugin, divided into multiple pages, if the list is long, (Actually my plugin shows the Admin Report of Questions Posted during a Specified Duration). I know there must be already built in functions which can do that for me, its just that I am not able to figure out, where and what they are.

Can anybody give me hints on which functions I should look at for doing the same?

1 Answer

+1 vote
by
edited by

Yes, there are plenty of functions you can use. You might find my user activity plugin helpful, which grabs some questions and lists them with pagination. See the process_request function in qa-user-activity.php.

Can't post all the code here since there is a character limit. As a quick summary, look at lines 58-61 of qa-user-activity.php. The first 2 lines make the query, the next 2 execute the query. You'd need to change the WHERE clause to match whatever you want to select. $start comes from the qa_get function and $pagesize comes from qa_opt.

Then I run another query to get the total number of questions, using the same WHERE clause as the above query (to make sure you're selecting the same set of questions). See the _questions_stats function, line 141. We end up with a $count variable, which we pass into the paging function below.

For the questions' HTML see lines 75-77:

    $qa_content['q_list']['qs']=array();
    foreach ( $questions as $question )
        $qa_content['q_list']['qs'][] = qa_any_to_q_html_fields($question, qa_get_logged_in_userid(), qa_cookie_get(), null, null, $htmloptions);

Note you need to make sure you've selected the right columns from qa_posts.

Finally, for the page numbers, see line 80:

    $qa_content['page_links'] = qa_html_page_links($request, $start, $pagesize, $count, qa_opt('pages_prev_next'), null);

Hope that helps!

by
Thanks a lot.... That's great help :)
...