PDA

View Full Version : Alternating Colors


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. :)

DjSap
27 Feb 2002, 14:16
thanks finally i can get that working

Bald Bouncer
02 Mar 2002, 19:32
firefly you a genius I just did what I needed to do in seconds, I even amazed myself ;)

jjj0923
10 Mar 2002, 18:17
pardon the newbie question, but I just installed purchased and installed vbulletin yesterday and I want to install this hack.

In which module do I install this code?

thanks in advance and pardon my ignorance.

all in all, I got purchased the product and had the forum up and running in about 3 hours...

- jeff

Chen
10 Mar 2002, 18:31
This is not a hack. You file hacks in the Full Releases forum, this just a forum to share small tips with other hackers. :)

jjj0923
10 Mar 2002, 18:40
thanks

s o r o k a
21 Apr 2002, 04:00
could you maybe give a bit of help on how to implement this please?