Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Q2A Core by

Add to your plugin or advanced theme the following (credits to Scott, user activity plugin):

function post_meta($post, $class, $prefix=null, $separator='<br/>')
    // default method call
    qa_html_theme_base::post_meta($post, $class, $prefix=null, $separator='<br/>');
    if($this->template=='user-answers') {
        $answerpreview = qa_db_read_one_value( qa_db_query_sub('SELECT content FROM `^posts`
                                                                    WHERE `parentid` = #
                                                                    ;', $post['raw']['postid']), true );
        // to avoid ugly content, convert answer to HTML then strip the tags and remove any URLs
        // $answerpreview = qa_viewer_html($answerpreview, 'html');
        $answerpreview = strip_tags( $answerpreview);
        $answerpreview = preg_replace('#\shttp://[^\s]+#', '', $answerpreview);
        $answerpreview = qa_substr($answerpreview, 0, 160);
        if($answerpreview == 160) {
            $answerpreview .= '…';                
            <div class="qa-a-snippet" style="margin-top: 2px;color: #555753;line-height: 115%;display:block;">

Q2A version: 1.7
PS: I know that this is not the prettiest, since I have to do a db query for each single item... but it works.

1 Answer

0 votes
Yes this is very inefficient. If you wanted to do this in the theme it would be better to start in the q_list function, get an array of all the postids, then run one query that gets the snippet for each answer. Like "SELECT ... WHERE postid IN (...)"

Then in the post_meta function you can output the snippet for that post.