Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.6k views
in Q2A Core by
You might want to give the span with class qa-a-count which indicates the number of answers for a question a different background.

For example, a red background if the number is 0 and a green background if the number is 1, 2, or more.

You can achieve this by extending your qa-theme.php file with:

_________________________________

function a_count($post) {
    if ($post['answers_raw'] > 0) {
        $this->output_split(@$post['answers'], 'qa-a-count-multiple', 'SPAN', 'SPAN',
        @$post['answer_selected'] ? 'qa-a-count-selected' : null);
    }
    else {
        $this->output_split(@$post['answers'], 'qa-a-count', 'SPAN', 'SPAN',
        @$post['answer_selected'] ? 'qa-a-count-selected' : null);
    }
}

_________________________________

 

Now search for .qa-a-count in your css file and add background: red to it.

Also add the class .qa-a-count-multiple and copy the contents of .qa-a-count to it, except for the background-color, this has to be green.

You might also have to add a .qa-a-count-multiple-data and qa-a-count-multipe-pad with the contents of qa-a-count-data and qa-a-count-data.

3 Answers

+1 vote
by
edited by
 
Best answer

There are already classes added if the question has 0 answers, or if it has a best answer selected. So you can just use this:

.qa-a-count.qa-a-count-zero {
    color: #a33;
}
.qa-a-count.qa-a-count-selected {
    color: #3a3;
}

UPDATE: sorry I forgot that I added the 'zero' class myself! The 'selected' class is definitely there, here is what the function is by default:

function a_count($post)
{
    // You can also use $post['answers_raw'] to get a raw integer count of answers
    $this->output_split(@$post['answers'], 'qa-a-count', 'SPAN', 'SPAN',
        @$post['answer_selected'] ? 'qa-a-count-selected' : null);
}

Here is what I changed the function to:

function a_count($post)
{
    $extraclass = null;
    if ( @$post['answers_raw'] == 0 )
        $extraclass = 'qa-a-count-zero';
    if ( @$post['answer_selected'] )
        $extraclass = 'qa-a-count-selected';

    $this->output_split(@$post['answers'], 'qa-a-count', 'SPAN', 'SPAN', $extraclass);
}

Now you can set the default colour on the qa-a-count class, then use the CSS above to override that if there are 0 answers, or an answer was selected.

If you need to style specific answers counts like 1, 2, 3 then you could do this and style appropriately:

    if ( @$post['answers_raw'] > 0 )
        $extraclass = 'qa-a-count-'.$post['answers_raw'];

 

by
Whoops! :-) Thank you, a lot easier.
by
I updated my answer, hope it helps!
By the way, this is not forum software. Answers are for answering the question, not replying to others ;)
by
Thanks, that did the job! :-)
0 votes
by

@DisgruntledGoat

Couldn't find those classes you are talking about.

All qa-a-count are the same in my version ( 1.4 beta1) ... whether they have 0 answers or not.

by
Are you using an advanced theme? You may be overwriting the function that adds those in. Check your version against qa-theme-base.php.
by
This is what I got in my advanced theme at the moment:

_______________________

function q_item_stats($question){
        $this->output('<DIV CLASS="qa-q-item-stats">');
        $this->cat_image($question);
        $this->a_count($question);
        $this->output('</DIV>');
}

function a_count($post) {
    if ($post['answers_raw'] > 0) {
        $this->output_split(@$post['answers'], 'qa-a-count-multiple', 'SPAN', 'SPAN',
        @$post['answer_selected'] ? 'qa-a-count-selected' : null);
    }
    else {
        $this->output_split(@$post['answers'], 'qa-a-count', 'SPAN', 'SPAN',
        @$post['answer_selected'] ? 'qa-a-count-selected' : null);
    }
}

_______________________

I restored a_count to the original code though, but still no classes added....
0 votes
by

@DisgruntledGoat

I even checked it on this website, even here there are no classes added.

Maybe you did understand me wrong.

I'm talking about the "0 answers", "1 answer" blocks on the frontpage where all the questions are listed... couldn't find any classes added to it...

...