Chen
25 Feb 2002, 07:34
Ok this is a pretty old 'trick' but I'm bored so here goes.
This is how you can get the effect of switching colors, like posts in vBulletin and such.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
At first we initalize $bgcounter to 0, so we know exactly what comes first (first or second color).
Then in the loop, we each time increment $bgcounter by one, so once it's an odd number and once it's even.
And last, inside the loop we check every time wheter $bgcounter is even or odd. This is done using the modulus operator (http://www.php.net/manual/en/language.operators.php).
If it's even, we get {firstaltcolor} in $bgcolor. Otherwise, we put there {secondaltcolor}.
Then all there's left to do is use $bgcolor in the template, and you will once get the first alternating color, and once the second. :)
This is how you can get the effect of switching colors, like posts in vBulletin and such.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
At first we initalize $bgcounter to 0, so we know exactly what comes first (first or second color).
Then in the loop, we each time increment $bgcounter by one, so once it's an odd number and once it's even.
And last, inside the loop we check every time wheter $bgcounter is even or odd. This is done using the modulus operator (http://www.php.net/manual/en/language.operators.php).
If it's even, we get {firstaltcolor} in $bgcolor. Otherwise, we put there {secondaltcolor}.
Then all there's left to do is use $bgcolor in the template, and you will once get the first alternating color, and once the second. :)