Last active
September 7, 2016 19:25
-
-
Save phlbnks/4ff428f387bfed30ab3a0cad24c50f08 to your computer and use it in GitHub Desktop.
Multiple modulus calculations for looping background colours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $posts is some content to loop over and output. Perhaps 28 items. | |
// We want raindow coloured boxes so loop over 7 possible colours. | |
$posts_count = 0; | |
foreach ( $posts as $post ) : | |
$colour = ''; | |
if ( $posts_count % 7 == 0 ) { | |
$colour = 'red'; | |
} elseif ( $posts_count % 7 == 1 ) { | |
$colour = 'orange'; | |
} elseif ( $posts_count % 7 == 2 ) { | |
$colour = 'yellow'; | |
} elseif ( $posts_count % 7 == 3 ) { | |
$colour = 'green'; | |
} elseif ( $posts_count % 7 == 4 ) { | |
$colour = 'blue'; | |
} elseif ( $posts_count % 7 == 5 ) { | |
$colour = 'indigo'; | |
} elseif ( $posts_count % 7 == 6 ) { | |
$colour = 'violet'; | |
} | |
echo '<div class="' . $colour . '">' . $post . '</div>'; | |
$posts_count++; | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment