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.

Apr 29: Q2A 1.5.2

Different background colors for 0 answers and 1,2,3, ... answers

0 votes
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.
asked May 28, 2011 in Q2A Core by Aslan

3 Answers

+1 vote
 
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'];

 

answered May 29, 2011 by DisgruntledGoat
edited Jun 1, 2011 by DisgruntledGoat
Whoops! :-) Thank you, a lot easier.
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 ;)
Thanks, that did the job! :-)
0 votes

@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.

answered May 29, 2011 by Aslan
Are you using an advanced theme? You may be overwriting the function that adds those in. Check your version against qa-theme-base.php.
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

@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...

answered Jun 1, 2011 by Aslan