Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+9 votes
261 views
in Plugins by
edited by

I'm developing my custom page, where I want to show some questions in a list.

Everything works fine, except for one thing. Each question on my list doesn't have a link. It's just empty and looks like this:

<a href="">Question title</a>

I retrieve questions with this function:

public function process_request($request)
    {
        $qa_content = qa_content_prepare();
        $qa_content['title'] = 'Page title';

        $questions = qa_db_select_with_pending(qa_db_qs_selectspec(null, 'created', 0, null, null, false, false, null));
        $qa_content['q_list']['qs'] = $questions;

        return $qa_content;
}

var_dump($qa_content['q_list']['qs']) gives me this:

    [1418] => Array
        (
            [postid] => 1418
            [categoryid] => 4
            [type] => Q
            [basetype] => Q
            [hidden] => 0
            [queued] => 0
            [acount] => 2
            [selchildid] => 
            [closedbyid] => 
            [upvotes] => 0
            [downvotes] => 0
            [netvotes] => 0
            [views] => 565
            [hotness] => 73206600000
            [flagcount] => 0
            [title] => Question title
            [tags] => tags list
            [created] => 1626604501
            [name] => 
            [categoryname] => Category Name
            [categorybackpath] => categorypath
            [categoryids] => 4,4
            [userid] => 14
            [cookieid] => 
            [createip] => 
            [points] => 730
            [flags] => 0
            [level] => 0
            [email] => user@email.com
            [handle] => Nickname
            [avatarblobid] => 
            [avatarwidth] => 
            [avatarheight] => 
            [_order_] => 49
        )

What am I doing wrong?

Update

I figured out, that ['url'] is missing from my array, so just before return in my function, I've added this:

        foreach($qa_content['q_list']['qs'] as $key => $value)
        {
            $url = qa_q_path($value['postid'], $value['title'], false);
            $qa_content['q_list']['qs'][$key]['url'] = $url;
        }

Is this approach right? It solves the problem, but shouldn't qa_db_qs_selectspec() function create URLs on its own?

Q2A version: 1.8.3

1 Answer

+1 vote
by

qa_db_qs_selectspec() is a database access function. It just provides raw data. From there, the processing starts. And the bad news for you is the URL is the least of your issues. For example, you should care about how to display the username of the user who last edited the question, or how to displayed a lock for closed questions, and those are just random examples.

Most of that stuff is already handled by Q2A. Your best bet is to look at how the qa_db_qa_selectspec() output is used, such as here. From there you can see how the qa_q_list_page_content() function is called and its code. The most relevant part of it is the foreach loop that calls qa_any_to_q_html_fields(), which might be relevant for your needs.

Strictly answering your question, qa_q_path() is a valid option. However, it all depends on how deep you want to get in the analysis. For example, you're not blocking inappropriate words in the title or adding microdate to it, and qa_post_html_fields() does that for you.

by
Thanks a lot! Actually, I looked at qa_q_list_page_content(), but couldn't get it to work. Even tried to copy-paste the code from questions.php or default.php without luck. What am I trying to do is to make an HTML sitemap page, which will contain a list of all questions.

Anyway, will keep trying and learning. Thanks for your tips.
...