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

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Jan 18: 1.5 release

Want to build a todays question feature, how to access a single question by its number in advanced theme ?

+4 votes
Hello,

I want to build this feature and have added in a special div each day another question of my choice.

The questions are allready in the system, now how do I access lets say question number 470 ?

How would I have to change this code, to load only question 470 ?

'<A HREF="'.$question['url'].'">'.$question['title'].'</A>'

Or is it much more complicated ?

Thanks so far

Monk333
asked Aug 21, 2010 in Q2A Core by monk333

1 Answer

0 votes
Try this:

$rawquestion=qa_db_single_select($qa_db,
    qa_db_full_post_selectspec(
        qa_get_logged_in_userid($qa_db),
        470
    )
);

You can then access the fields you want from $rawquestion, which will be raw information from the database, not already formatted for HTML. Use print_r() to get an idea of all the fields it contains.

You can get the title to display from qa_html($rawquestion['title']) and the URL from qa_path_html(qa_q_request($rawquestion['postid'], $rawquestion['title'])) - look in function qa_post_html_fields(...) in qa-app-format.php for other ways to convert raw Q info into HTML.
answered Aug 23, 2010 by gidgreen
I found something regarding the database:

qa_pregpages--> VALUES (4, 'daily', '_', 1, 0, 'daily', '', '470');

There the number of the daily page (470 here) is stored.

I as well found the function to get the content of the pages:

qa_db_page_full_selectspec($slugorpageid, $ispageid)

But I cant write the function to get the questionnumber into a variable.

Shouldnt be so complicated, but i am still a beginner. Someone ? Thank You so much.
Your best option is to store the question number in the qa_options table.

First choose a name for the option like 'daily_question_id'.

Then add this to the $showoptions array in one of the 'case's near the top qa-page-admin.php, depending on which page you want it to show on.

You can then get the value of this option from within the theme code using qa_get_option($qa_db, 'daily_question_id') - pass that instead of 470.