我正在使用 php if 语句向与评级相关的 div 添加类:
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>
输出示例:
<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>
我不知道如何组织 PHP 部分。上面我描述了这个想法,但该代码无法正常工作。
有人对安排这些 php if 语句有什么建议吗?
最佳答案
<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>
关于php - 如何安排这个输出评级(好、很棒、优秀等)的 php if 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120113/