I'm using php if-statements to add classes to divs that are related to rating:
CSS:
.average .rating-result {
color: #888; /* 0~1 votes */
}
.good .rating-result {
color: #9a6e65; /* 2~3 votes */
}
.great .rating-result {
color: #aa5443; /* 4~5 votes */
}
.excellent .rating-result {
color: #bb3b22; /* 6~7 votes */
}
.brilliant .rating-result {
color: #cc2200; /* 8~9 votes */
}
PHP:
<div class="topic-like-count<?php if ( $thumbs_number == 0 || 1 ) {
echo " good"; } elseif ( $thumbs_number == 2 || 3 ) { echo " great"; }
elseif ( $thumbs_number == 4 || 5 ) { echo " excellent"; } elseif (
$thumbs_number > 6 || 7 ) { echo " brilliant"; } else { echo "
average"; }?>"> h4><?php wp_gdsr_render_article_thumbs(); ?></h4>
</div>
OUTPUT example:
<div class="topic-like-count good">
<h4>
<div style="display: none">UA:D [1.9.10_1130]</div>
<div class="thumblock ">
<span class="rating-result">4</span>
<div class="ratingtext ">
<div class="raterclear"></div>
</div>
</h4>
</div>
I'm not sure how to organize the PHP part. Above I discribed the idea but that code doesn't work properly.
Does anyone have any suggestion to arrange these php if-statements?
<div class="topic-like-count
<?php
switch ($thumbs_number) {
case 0:
case 1: echo ' good'; break;
case 2:
case 3: echo ' great'; break;
case 4:
case 5: echo ' excellent'; break;
case 6:
case 7: echo ' brilliant'; break;
default: echo ' average'; break;
}
?>
">
<h4><?php wp_gdsr_render_article_thumbs(); ?></h4>
</div>
This will cause it to always display good.
|| 1
<?php if ( $thumbs_number == 0 || $thumbs_number ==1 ) {
echo " good"; } elseif ( $thumbs_number == 2 || $thumbs_number ==3 ) { echo " great"; }
elseif ( $thumbs_number == 4 || $thumbs_number ==5 ) { echo " excellent"; } elseif (
$thumbs_number > 6 || $thumbs_number ==7 ) { echo " brilliant"; } else { echo "
average"; }
?>
Your if syntax is wrong: if ( $thumbs_number == 0 || 1 )
evaluates to: if ( ($thumbs_number == 0) || 1)
which is always true.
You should write: if ( $thumbs_number == 0 || $thumbs_number == 1 )
It would make more sense to incorporate this in a switch statment;
switch ( $thumbs_number ) {
case 0:
case 1:
$rating = 'good';
break;
case 2:
case 3:
$rating = 'great';
break;
// etc ...
}
?>
<div class="topic-like-count <?=$rating?>">