Basically, I would like to turn the following switch-statement (which is in a Wordpress template file):
<?php preg_match( '!<div class="thumblock ">(.*)</div>!si' , wp_gdsr_render_article_thumbs(0, false, "", 0, "", false) , $n );
$thumbs_number = strip_tags( $n[1] ); ?>
<div class="topic-like-count
<?php // Apply style based on number of votes
switch ($thumbs_number) {
case ($thumbs_number == 0):
case ($thumbs_number == 1): echo ' average'; break;
case ($thumbs_number == 2):
case ($thumbs_number == 3): echo ' good'; break;
case ($thumbs_number == 4):
case ($thumbs_number == 5): echo ' great'; break;
case ($thumbs_number == 6):
case ($thumbs_number == 7): echo ' excellent'; break;
default:
if ($thumbs_number <= -1) echo "bad";
else if ($thumbs_number > 7) echo "brillant";
}
?>
">
<h4><?php wp_gdsr_render_article_thumbs(); ?></h4>
<?php if ( $thumbs_number == 1 || $thumbs_number == -1 ) : ?>
<span><?php _e( 'vote' ); ?></span>
<?php else : ?>
<span><?php _e( 'votes' ); ?></span>
<?php endif; ?>
</div>
into a function (stored in functions.php) that I can use like this in a template:
<?php rating_class(); ?>
Any suggestions?
(The question has a bit of Worpdress but I think it is more a php question)