Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.1k views
in Q2A Core by

In the user questions list we have a "selected" class (for each question that has a selcted answer) which is easily to target by CSS.

Example: https://www.question2answer.org/qa/user/pupi1985/questions

See source and find: <span class="qa-a-count qa-a-count-selected">

I like to display the same class for the answers of each user on their answers list page. But the class qa-a-count-selected does not exist on this page. See example HTML at: https://www.question2answer.org/qa/user/pupi1985/answers

How to add this class? So that the user knows which of his/her answers was selected.

Q2A version: 1.8.1

1 Answer

+1 vote
by

Alright, found the solution myself. Add this override to your qa-theme.php:

// override function vote_count($post)
public function vote_count($post)
{
    // You can also use $post['upvotes_raw'], $post['downvotes_raw'], $post['netvotes_raw'] to get
    // raw integer vote counts, for graphing or showing in other non-textual ways

    $this->output('<div class="qa-vote-count ' . (($post['vote_view'] == 'updown') ? 'qa-vote-count-updown' : 'qa-vote-count-net') . '"' . @$post['vote_count_tags'] . '>');

    if ($post['vote_view'] == 'updown') {
        $this->output_split($post['upvotes_view'], 'qa-upvote-count');
        $this->output_split($post['downvotes_view'], 'qa-downvote-count');
    } else {
        $this->output_split($post['netvotes_view'], 'qa-netvote-count');
    }
    
    // q2apro: show selected answer on user-answers list
    if($this->template == 'user-answers')
    {
        $selectedanswer = $post['raw']['selchildid'];
        $recentanswer = $post['raw']['opostid'];
        if($selectedanswer == $recentanswer)
        {
            $this->output('<span class="qa-a-count qa-a-count-selected"></span>');
        }
    }
    
    $this->output('</div>');
}
...